Advertisement
riking

Prevent overpowered enchants

Oct 15th, 2013
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1.  
  2.     @EventHandler
  3.     public void onSpawnItem(InventoryCreativeEvent ev) {
  4.         // Ignore NPCs
  5.         if (!(ev.getWhoClicked() instanceof Player)) return;
  6.  
  7.         ItemStack item = ev.getCursor();
  8.         ItemMeta meta = item.getItemMeta();
  9.         if (meta == null) return;
  10.         Map<Enchantment, Integer> enchants = meta.getEnchants();
  11.         for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
  12.             if (entry.getValue().intValue() > 5) {
  13.                 ev.setCancelled(true);
  14.                 Player p = (Player) ev.getWhoClicked();
  15.                 p.sendMessage("Nuh-uh-uh! Dirty cheater!");
  16.             }
  17.         }
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement