Removing enchants from players armor

Discussion in 'Plugin Development' started by _Lotuz217, Mar 31, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    _Lotuz217

    I try to make that if player moves and he's armor enchantment level is bigger than durability 1 it will be set to durability 1.
    Sorry 4 my bad english..
    Code:
            if ((player.getInventory().getHelmet().getType() != null && player.getInventory().getHelmet().getEnchantmentLevel(Enchantment.DURABILITY) != 1 && player.getInventory().getHelmet().getEnchantmentLevel(Enchantment.DURABILITY) == 2) || player.getInventory().getHelmet().getEnchantmentLevel(Enchantment.DURABILITY) == 3) {
                   ((Player) event.getPlayer()).sendMessage(ChatColor.RED + " Heh, szmieszek z ciebie. cos ci nie pyklo ;)");
                   player.getInventory().getHelmet().removeEnchantment(Enchantment.DURABILITY);
                   player.getInventory().getHelmet().addEnchantment(Enchantment.DURABILITY, 1);
            }
     
  2. that returns a clone of the helmet, just like any other method to get items from an inventory.
    modifying that clone won't modify the item in the inventory, so you need to store it in a variable, modify it and set it as the new helmet with .setHelmet(item);
     
    Last edited: Mar 31, 2017
  3. Offline

    MrTygo

    Change the if to isnt 0, so it will be either 1, 2 or 3. Just to make the code a little bit shorter ;)
     
Thread Status:
Not open for further replies.

Share This Page