Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import org.bukkit.ChatColor;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.Configuration;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.gmail.nossr50.datatypes.skills.SkillType;
- import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
- public class TestPlugin extends JavaPlugin implements Listener {
- @Override
- public void onEnable() {
- saveDefaultConfig();
- getServer().getPluginManager().registerEvents(this, this);
- getCommand("mcxpperks").setExecutor(this);
- validateConfig(getConfig());
- }
- private void validateConfig(ConfigurationSection config) {
- ConfigurationSection playersSection = config.getConfigurationSection("players");
- for (String plName : playersSection.getKeys(false)) {
- OfflinePlayer op = getServer().getOfflinePlayer(plName);
- if (!op.hasPlayedBefore()) {
- getLogger().warning(plName + " has not played on this server, but they are in the config file!");
- }
- ConfigurationSection subSection = playersSection.getConfigurationSection(plName);
- for (String skName : subSection.getKeys(false)) {
- SkillType skilltype = SkillType.valueOf(skName);
- if (skilltype == null) {
- getLogger().warning(skName + " is not a valid skill name (found in " + plName + "'s section)");
- } else if (!skilltype.name().toLowerCase().equals(skName)) {
- getLogger().warning("Please use '" + skilltype.name().toLowerCase() + "' instead of '" + skName + "'.");
- }
- }
- }
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- this.reloadConfig();
- sender.sendMessage(ChatColor.AQUA + "Reloaded mcMMO XP Perks config");
- return true;
- }
- @EventHandler
- public void onXp(McMMOPlayerXpGainEvent event) {
- event.setRawXpGained((float) (event.getRawXpGained() * getMultiplier(event.getPlayer(), event.getSkill())));
- }
- private double getMultiplier(Player player, SkillType skill) {
- return getConfig().getDouble("players." + player.getName() + "." + skill.name().toLowerCase(), 1D);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement