Advertisement
riking

CustomMcmmoXpPerks

Sep 15th, 2013
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. package test;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.OfflinePlayer;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.configuration.Configuration;
  8. import org.bukkit.configuration.ConfigurationSection;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. import com.gmail.nossr50.datatypes.skills.SkillType;
  15. import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
  16.  
  17. public class TestPlugin extends JavaPlugin implements Listener {
  18.  
  19.     @Override
  20.     public void onEnable() {
  21.         saveDefaultConfig();
  22.         getServer().getPluginManager().registerEvents(this, this);
  23.         getCommand("mcxpperks").setExecutor(this);
  24.         validateConfig(getConfig());
  25.     }
  26.  
  27.     private void validateConfig(ConfigurationSection config) {
  28.         ConfigurationSection playersSection = config.getConfigurationSection("players");
  29.         for (String plName : playersSection.getKeys(false)) {
  30.             OfflinePlayer op = getServer().getOfflinePlayer(plName);
  31.             if (!op.hasPlayedBefore()) {
  32.                 getLogger().warning(plName + " has not played on this server, but they are in the config file!");
  33.             }
  34.             ConfigurationSection subSection = playersSection.getConfigurationSection(plName);
  35.             for (String skName : subSection.getKeys(false)) {
  36.                 SkillType skilltype = SkillType.valueOf(skName);
  37.                 if (skilltype == null) {
  38.                     getLogger().warning(skName + " is not a valid skill name (found in " + plName + "'s section)");
  39.                 } else if (!skilltype.name().toLowerCase().equals(skName)) {
  40.                     getLogger().warning("Please use '" + skilltype.name().toLowerCase() + "' instead of '" + skName + "'.");
  41.                 }
  42.             }
  43.         }
  44.     }
  45.  
  46.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  47.         this.reloadConfig();
  48.         sender.sendMessage(ChatColor.AQUA + "Reloaded mcMMO XP Perks config");
  49.         return true;
  50.     }
  51.  
  52.     @EventHandler
  53.     public void onXp(McMMOPlayerXpGainEvent event) {
  54.         event.setRawXpGained((float) (event.getRawXpGained() * getMultiplier(event.getPlayer(), event.getSkill())));
  55.     }
  56.  
  57.     private double getMultiplier(Player player, SkillType skill) {
  58.         return getConfig().getDouble("players." + player.getName() + "." + skill.name().toLowerCase(), 1D);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement