Call PlayerItemDamageEvent for tridents (#11899)

This commit is contained in:
Tamion
2025-01-13 00:29:52 +01:00
committed by GitHub
parent 5e23d28ad2
commit ab1b312064
2 changed files with 29 additions and 3 deletions

View File

@@ -292,7 +292,33 @@
this.shrink(1);
onBreak.accept(item);
}
@@ -512,9 +_,14 @@
@@ -506,15 +_,39 @@
return;
}
- int min = Math.min(this.getDamageValue() + i, this.getMaxDamage() - 1);
+ int min = Math.min(this.getDamageValue() + i, this.getMaxDamage() - 1); // Paper - Expand PlayerItemDamageEvent - diff on change as min computation is copied post event.
+
+ // Paper start - Expand PlayerItemDamageEvent
+ if (min - this.getDamageValue() > 0) {
+ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent(
+ serverPlayer.getBukkitEntity(),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this),
+ min - this.getDamageValue(),
+ damage
+ );
+ if (!event.callEvent() || event.getDamage() == 0) {
+ return;
+ }
+
+ // Prevent breaking the item in this code path as callers may expect the item to survive
+ // (given the method name)
+ min = Math.min(this.getDamageValue() + event.getDamage(), this.getMaxDamage() - 1);
+ }
+ // Paper end - Expand PlayerItemDamageEvent
+
this.applyDamage(min, serverPlayer, item -> {});
}
}
public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {