The API allows developers to access the global Player leveler and assign players XP or a specific level. You can also register Custom reward types and reward auto-correctors.
Add the API to your project
Maven (not recommended)
I won't help you if you use Maven. Use gradle. You might also need to include Aikars ACF repo when you use maven.
Player player = ...;
double xp = ...;
leveler.addXpToPlayer(player, xp);
// Or set the player level to something
long newLevel = 10;
leveler.setPlayerLevel(player, newLevel);
Add custom reward types
Example command reward. (This is already implemented.)
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import gg.auroramc.aurora.api.command.CommandDispatcher;
import gg.auroramc.aurora.api.message.Placeholder;
import gg.auroramc.aurora.api.reward.AbstractReward;
import java.util.List;
public class CommandReward extends AbstractReward {
private String command;
@Override
public void execute(Player player, long level, List<Placeholder<?>> placeholders) {
if (command == null) return;
CommandDispatcher.dispatch(player, command, placeholders);
}
@Override
public void init(ConfigurationSection args) {
// Always call super.init here!
super.init(args);
command = args.getString("command", null);
}
}
Example money reward. (This is already implemented.)
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import gg.auroramc.aurora.api.command.CommandDispatcher;
import gg.auroramc.aurora.api.message.Placeholder;
import gg.auroramc.aurora.api.AuroraAPI;
import gg.auroramc.aurora.api.reward.NumberReward;
import java.util.List;
public class MoneyReward extends NumberReward {
private String economy;
@Override
public void execute(Player player, long level, List<Placeholder<?>> placeholders) {
var econ = AuroraAPI.getEconomy(economy);
if(econ == null) econ = AuroraAPI.getDefaultEconomy();
econ.deposit(player, getValue(placeholders));
}
@Override
public void init(ConfigurationSection args) {
super.init(args);
economy = args.getString("economy", "Vault");
}
}
Register your rewards (This has to happen on your plugins onEnable lifecycle method)
RewardFactory factory = leveler.getRewardFactory();
// This will be an available reward type in config
// Just use plugin-name/reward-name to reference it.
factory.registerRewardType(NamespacedId.of("plugin-name", "reward-name"), YourRewardClass.class);
Register a reward corrector (This has to happen on your plugins onEnable lifecycle method)
import gg.auroramc.aurora.api.reward.RewardCorrector;
import org.bukkit.entity.Player;
public class MyCorrector implements RewardCorrector {
@Override
public void correctRewards(Player player) {
// do your thing
}
}
leveler.getRewardAutoCorrector()
.registerCorrector(NamespacedId.of("plugin-name", "corrector-name"), new MyCorrector());