SPIGOT-7895: PlayerItemBreakEvent not firing

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2024-09-09 20:57:37 +10:00
parent deb7197a64
commit b7359583f2
2 changed files with 13 additions and 13 deletions

View file

@ -302,18 +302,18 @@
if (i <= 0) { if (i <= 0) {
return; return;
} }
@@ -480,6 +694,11 @@ @@ -458,6 +672,11 @@
} this.setDamageValue(j);
if (j >= this.getMaxDamage()) {
Item item = this.getItem();
+ // CraftBukkit start - Check for item breaking
+ if (this.count == 1) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(entityplayer, this);
+ }
+ // CraftBukkit end
this.hurtAndBreak(i, worldserver, entityplayer, (item) -> { this.shrink(1);
+ // CraftBukkit start - Check for item breaking consumer.accept(item);
+ if (this.count == 1 && entityliving instanceof EntityHuman) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) entityliving, this);
+ }
+ // CraftBukkit end
entityliving.onEquippedItemBroken(item, enumitemslot);
});
}
@@ -693,6 +912,12 @@ @@ -693,6 +912,12 @@
return this.getItem().useOnRelease(this); return this.getItem().useOnRelease(this);
} }

View file

@ -1365,9 +1365,9 @@ public class CraftEventFactory {
return event; return event;
} }
public static void callPlayerItemBreakEvent(EntityHuman human, ItemStack brokenItem) { public static void callPlayerItemBreakEvent(EntityPlayer human, ItemStack brokenItem) {
CraftItemStack item = CraftItemStack.asCraftMirror(brokenItem); CraftItemStack item = CraftItemStack.asCraftMirror(brokenItem);
PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item); PlayerItemBreakEvent event = new PlayerItemBreakEvent(human.getBukkitEntity(), item);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
} }