1.8.8 PlayerItemDamageEvent

Discussion in 'Spigot Plugin Development' started by AloPace, Aug 2, 2020 at 3:12 PM.

  1. When I break blocks, It still breaks the item it isn't actually broken, I have to press the drop key and It comes back, anyone now a fix?

    Code:
    Code (Text):

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemDamageEvent;

    public class UnbreakableItems implements Listener {

        @EventHandler
        public void onItemDamage(PlayerItemDamageEvent e) {
            e.setCancelled(true);
        }
    }
     
  2. Set the durability to max
     
  3. Tried that, still doesn't work
     
  4. Send your code
     
  5. Code (Text):
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemDamageEvent;

    public class UnbreakableItems implements Listener {

        @EventHandler
        public void onItemDamage(PlayerItemDamageEvent e) {
            e.getItem().setDurability((short) 0);
        }
    }
     
  6. try updating the player's inventory:
    e.getPlayer().updateInventory();
     
  7. That now makes it so the e.setCancelled(); doesn't work
     
  8. Have you tried event#setDamage(int)? Worked for me when I was trying to create unbreakable items.