Solved How to check an item for enchantment?

Discussion in 'Spigot Plugin Development' started by Super02, Jun 19, 2018.

  1. Hello, I'm making a plugin where if you kill someone you get their head and sell it for money when you right click on it. Well, so the problem is that I'm not sure how to test if it's a legit player head. I have added an Unbreaking level 100 to the head but how do I check if the head the player has in his inventory is a player head and if it has unbreaking 100?

    Thanks for the help in advance :)
     
  2. This is untested, but should work, just might require a bit of fixing

    Code (Java):
    if (item.getType() == Material.SKULL_ITEM // Check that it's a skull item
    && item.getData().getData() == 3 // Check that it's of type 3, a player skull
    && item.getEnchantmentLevel(Enchantment.DURABILITY) == 100) // Check that it has unbreaking 100 {
         ...
    }
     
    • Useful Useful x 1
  3. Thanks! But is there a way where the .getData() is not deprecated?
     
  4. I wouldn't worry about it too much, the non-deprecated way to do it will also break in 1.13 anyway.
     
    • Useful Useful x 1
  5. Ok, thanks so much for the help :)
     
    • Like Like x 1