From 9f37f705272d633c8cf316b3522833ad6441c1d9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 6 May 2012 21:38:01 -0600 Subject: [PATCH] Fire PlayerItemBreakEvent. Addresses BUKKIT-1600 --- src/main/java/net/minecraft/server/ItemStack.java | 6 ++++++ .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java index 5366f45f15..a444c71376 100644 --- a/src/main/java/net/minecraft/server/ItemStack.java +++ b/src/main/java/net/minecraft/server/ItemStack.java @@ -179,6 +179,12 @@ public final class ItemStack { this.count = 0; } + // CraftBukkit start - Check for item breaking + if (this.count == 0 && entityliving instanceof EntityHuman) { + org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) entityliving, this); + } + // CraftBukkit end + this.damage = 0; } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 79ad5256e8..ffd5b4422e 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -526,4 +526,10 @@ public class CraftEventFactory { world.getServer().getPluginManager().callEvent(event); return event; } + + public static void callPlayerItemBreakEvent(EntityHuman human, ItemStack brokenItem) { + CraftItemStack item = new CraftItemStack(brokenItem); + PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item); + Bukkit.getPluginManager().callEvent(event); + } }