Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EnchantBlockListener implements Listener {
- @EventHandler
- public void onAnvilUse(InventoryClickEvent e) {
- if (e.getView().getType().equals(InventoryType.ANVIL)) {
- int rawSlot = e.getRawSlot();
- if (rawSlot == 2) {
- ItemStack itemStack = e.getCurrentItem();
- if (itemStack != null) {
- ItemMeta itemMeta = itemStack.getItemMeta();
- Player player = (Player)e.getWhoClicked();
- if (itemMeta != null) {
- if (itemStack.getType() == Material.BOW &&
- itemMeta.getEnchants().get(Enchantment.ARROW_INFINITE) != null) {
- itemMeta.removeEnchant(Enchantment.ARROW_INFINITE);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Nieskonczonosc` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.DIAMOND_SWORD &&
- itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL)).intValue() >= 5) {
- itemMeta.removeEnchant(Enchantment.DAMAGE_ALL);
- itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 4, true);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc V` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.IRON_SWORD) {
- if (itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DAMAGE_ALL)).intValue() >= 4) {
- itemMeta.removeEnchant(Enchantment.DAMAGE_ALL);
- itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 3, true);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc IV-V` jest zablokowany dla tego przedmiotu!");
- }
- if (itemMeta.getEnchants().get(Enchantment.FIRE_ASPECT) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.FIRE_ASPECT)).intValue() >= 1) {
- itemMeta.removeEnchant(Enchantment.FIRE_ASPECT);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Fire Aspect I-II` jest zablokowany dla tego przedmiotu!");
- }
- }
- if ((itemStack.getType() == Material.IRON_HELMET || itemStack
- .getType() == Material.IRON_CHESTPLATE || itemStack
- .getType() == Material.IRON_LEGGINGS || itemStack
- .getType() == Material.IRON_BOOTS) &&
- itemMeta.getEnchants().get(Enchantment.DURABILITY) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DURABILITY)).intValue() >= 3) {
- itemMeta.removeEnchant(Enchantment.DURABILITY);
- itemMeta.addEnchant(Enchantment.DURABILITY, 2, true);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.DIAMOND_HELMET || itemStack
- .getType() == Material.DIAMOND_CHESTPLATE || itemStack
- .getType() == Material.DIAMOND_LEGGINGS || itemStack
- .getType() == Material.DIAMOND_BOOTS) {
- if (itemMeta.getEnchants().get(Enchantment.DURABILITY) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.DURABILITY)).intValue() >= 3) {
- itemMeta.removeEnchant(Enchantment.DURABILITY);
- itemMeta.addEnchant(Enchantment.DURABILITY, 2, true);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
- }
- if (itemMeta.getEnchants().get(Enchantment.PROTECTION_ENVIRONMENTAL) != null && ((Integer)itemMeta.getEnchants().get(Enchantment.PROTECTION_ENVIRONMENTAL)).intValue() >= 4) {
- itemMeta.removeEnchant(Enchantment.PROTECTION_ENVIRONMENTAL);
- itemMeta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
- itemStack.setItemMeta(itemMeta);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ochrona IV` jest zablokowany dla tego przedmiotu!");
- }
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onEnchantItem(EnchantItemEvent e) {
- ItemStack itemStack = e.getItem();
- Player player = e.getEnchanter();
- if (itemStack.getType() == Material.BOW &&
- e.getEnchantsToAdd().get(Enchantment.ARROW_INFINITE) != null) {
- e.getEnchantsToAdd().remove(Enchantment.ARROW_INFINITE);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Nieskonczonosc` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.DIAMOND_SWORD &&
- e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL)).intValue() >= 5) {
- e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, Integer.valueOf(4));
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc V` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.IRON_SWORD || itemStack.getType() == Material.DIAMOND_SWORD) {
- if (e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DAMAGE_ALL)).intValue() >= 4) {
- e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, Integer.valueOf(3));
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ostrosc IV-V` jest zablokowany dla tego przedmiotu!");
- }
- if (e.getEnchantsToAdd().get(Enchantment.FIRE_ASPECT) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.FIRE_ASPECT)).intValue() >= 1) {
- e.getEnchantsToAdd().remove(Enchantment.FIRE_ASPECT);
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Fire Aspect I-II` jest zablokowany dla tego przedmiotu!");
- }
- }
- if ((itemStack.getType() == Material.IRON_HELMET || itemStack
- .getType() == Material.IRON_CHESTPLATE || itemStack
- .getType() == Material.IRON_LEGGINGS || itemStack
- .getType() == Material.IRON_BOOTS) &&
- e.getEnchantsToAdd().get(Enchantment.DURABILITY) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DURABILITY)).intValue() >= 3) {
- e.getEnchantsToAdd().put(Enchantment.DURABILITY, Integer.valueOf(2));
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
- }
- if (itemStack.getType() == Material.DIAMOND_HELMET || itemStack
- .getType() == Material.DIAMOND_CHESTPLATE || itemStack
- .getType() == Material.DIAMOND_LEGGINGS || itemStack
- .getType() == Material.DIAMOND_BOOTS) {
- if (e.getEnchantsToAdd().get(Enchantment.DURABILITY) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.DURABILITY)).intValue() >= 3) {
- e.getEnchantsToAdd().put(Enchantment.DURABILITY, Integer.valueOf(2));
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Niezniszczalnosc III` jest zablokowany dla tego przedmiotu!");
- }
- if (e.getEnchantsToAdd().get(Enchantment.PROTECTION_ENVIRONMENTAL) != null && ((Integer)e.getEnchantsToAdd().get(Enchantment.PROTECTION_ENVIRONMENTAL)).intValue() >= 4) {
- e.getEnchantsToAdd().put(Enchantment.PROTECTION_ENVIRONMENTAL, Integer.valueOf(3));
- ChatUtil.sendMessage((CommandSender)player, "&cEnchant `Ochrona IV` jest zablokowany dla tego przedmiotu!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement