Advertisement
imBEheAR

Untitled

May 10th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.67 KB | None | 0 0
  1.  
  2. public class EnchantBlockListener implements Listener {
  3.   @EventHandler
  4.   public void onAnvilUse(InventoryClickEvent e) {
  5.     if (e.getView().getType().equals(InventoryType.ANVIL)) {
  6.       int rawSlot = e.getRawSlot();
  7.       if (rawSlot == 2) {
  8.         ItemStack itemStack = e.getCurrentItem();
  9.         if (itemStack != null) {
  10.           ItemMeta itemMeta = itemStack.getItemMeta();
  11.           Player player = (Player)e.getWhoClicked();
  12.           if (itemMeta != null) {
  13.             if (itemStack.getType() == Material.BOW &&
  14.               itemMeta.getEnchants().get(Enchantment.ARROW_INFINITE) != null) {
  15.               itemMeta.removeEnchant(Enchantment.ARROW_INFINITE);
  16.               itemStack.setItemMeta(itemMeta);
  17.               ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Nieskonczonosc` jest zablokowany dla tego przedmiotu!");
  18.             }
  19.             if (itemStack.getType() == Material.DIAMOND_SWORD &&
  20.               itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL)).intValue() >= 5) {
  21.               itemMeta.removeEnchant(Enchantment.DAMAGE_ALL);
  22.               itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 4, true);
  23.               itemStack.setItemMeta(itemMeta);
  24.               ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc V` jest zablokowany dla tego przedmiotu!");
  25.             }
  26.             if (itemStack.getType() == Material.IRON_SWORD) {
  27.               if (itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL)).intValue() >= 4) {
  28.                 itemMeta.removeEnchant(Enchantment.DAMAGE_ALL);
  29.                 itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 3, true);
  30.                 itemStack.setItemMeta(itemMeta);
  31.                 ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc IV-V` jest zablokowany dla tego przedmiotu!");
  32.               }
  33.               if (itemMeta.getEnchants().get(Enchantment.FIRE_ASPECT) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.FIRE_ASPECT)).intValue() >= 1) {
  34.                 itemMeta.removeEnchant(Enchantment.FIRE_ASPECT);
  35.                 itemStack.setItemMeta(itemMeta);
  36.                 ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Fire Aspect I-II` jest zablokowany dla tego przedmiotu!");
  37.               }
  38.             }
  39.             if ((itemStack.getType() == Material.IRON_HELMET || itemStack
  40.               .getType() == Material.IRON_CHESTPLATE || itemStack
  41.               .getType() == Material.IRON_LEGGINGS || itemStack
  42.               .getType() == Material.IRON_BOOTS) &&
  43.               itemMeta.getEnchants().get(Enchantment.DURABILITY) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DURABILITY)).intValue() >= 3) {
  44.               itemMeta.removeEnchant(Enchantment.DURABILITY);
  45.               itemMeta.addEnchant(Enchantment.DURABILITY, 2, true);
  46.               itemStack.setItemMeta(itemMeta);
  47.               ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
  48.             }
  49.             if (itemStack.getType() == Material.DIAMOND_HELMET || itemStack
  50.               .getType() == Material.DIAMOND_CHESTPLATE || itemStack
  51.               .getType() == Material.DIAMOND_LEGGINGS || itemStack
  52.               .getType() == Material.DIAMOND_BOOTS) {
  53.               if (itemMeta.getEnchants().get(Enchantment.DURABILITY) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DURABILITY)).intValue() >= 3) {
  54.                 itemMeta.removeEnchant(Enchantment.DURABILITY);
  55.                 itemMeta.addEnchant(Enchantment.DURABILITY, 2, true);
  56.                 itemStack.setItemMeta(itemMeta);
  57.                 ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
  58.               }
  59.               if (itemMeta.getEnchants().get(Enchantment.PROTECTION_ENVIRONMENTAL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.PROTECTION_ENVIRONMENTAL)).intValue() >= 4) {
  60.                 itemMeta.removeEnchant(Enchantment.PROTECTION_ENVIRONMENTAL);
  61.                 itemMeta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
  62.                 itemStack.setItemMeta(itemMeta);
  63.                 ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ochrona IV` jest zablokowany dla tego przedmiotu!");
  64.               }
  65.             }
  66.           }
  67.         }
  68.       }
  69.     }
  70.   }
  71.  
  72.   @EventHandler
  73.   public void onEnchantItem(EnchantItemEvent e) {
  74.     ItemStack itemStack = e.getItem();
  75.     Player player = e.getEnchanter();
  76.     if (itemStack.getType() == Material.BOW &&
  77.       e.getEnchantsToAdd().get(Enchantment.ARROW_INFINITE) != null) {
  78.       e.getEnchantsToAdd().remove(Enchantment.ARROW_INFINITE);
  79.       ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Nieskonczonosc` jest zablokowany dla tego przedmiotu!");
  80.     }
  81.     if (itemStack.getType() == Material.DIAMOND_SWORD &&
  82.       e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL)).intValue() >= 5) {
  83.       e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, Integer.valueOf(4));
  84.       ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc V` jest zablokowany dla tego przedmiotu!");
  85.     }
  86.     if (itemStack.getType() == Material.IRON_SWORD || itemStack.getType() == Material.DIAMOND_SWORD) {
  87.       if (e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL)).intValue() >= 4) {
  88.         e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, Integer.valueOf(3));
  89.         ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc IV-V` jest zablokowany dla tego przedmiotu!");
  90.       }
  91.       if (e.getEnchantsToAdd().get(Enchantment.FIRE_ASPECT) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.FIRE_ASPECT)).intValue() >= 1) {
  92.         e.getEnchantsToAdd().remove(Enchantment.FIRE_ASPECT);
  93.         ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Fire Aspect I-II` jest zablokowany dla tego przedmiotu!");
  94.       }
  95.     }
  96.     if ((itemStack.getType() == Material.IRON_HELMET || itemStack
  97.       .getType() == Material.IRON_CHESTPLATE || itemStack
  98.       .getType() == Material.IRON_LEGGINGS || itemStack
  99.       .getType() == Material.IRON_BOOTS) &&
  100.       e.getEnchantsToAdd().get(Enchantment.DURABILITY) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DURABILITY)).intValue() >= 3) {
  101.       e.getEnchantsToAdd().put(Enchantment.DURABILITY, Integer.valueOf(2));
  102.       ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
  103.     }
  104.     if (itemStack.getType() == Material.DIAMOND_HELMET || itemStack
  105.       .getType() == Material.DIAMOND_CHESTPLATE || itemStack
  106.       .getType() == Material.DIAMOND_LEGGINGS || itemStack
  107.       .getType() == Material.DIAMOND_BOOTS) {
  108.       if (e.getEnchantsToAdd().get(Enchantment.DURABILITY) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DURABILITY)).intValue() >= 3) {
  109.         e.getEnchantsToAdd().put(Enchantment.DURABILITY, Integer.valueOf(2));
  110.         ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
  111.       }
  112.       if (e.getEnchantsToAdd().get(Enchantment.PROTECTION_ENVIRONMENTAL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.PROTECTION_ENVIRONMENTAL)).intValue() >= 4) {
  113.         e.getEnchantsToAdd().put(Enchantment.PROTECTION_ENVIRONMENTAL, Integer.valueOf(3));
  114.         ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ochrona IV` jest zablokowany dla tego przedmiotu!");
  115.       }
  116.     }
  117.   }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement