mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
Fix ItemDamageEvents called for 0 damage (#11900)
This commit is contained in:
parent
f367f107cf
commit
9f90b4c324
1 changed files with 4 additions and 3 deletions
|
@ -218,6 +218,7 @@
|
||||||
|
|
||||||
- public void hurtAndBreak(int damage, ServerLevel level, @Nullable ServerPlayer player, Consumer<Item> onBreak) {
|
- public void hurtAndBreak(int damage, ServerLevel level, @Nullable ServerPlayer player, Consumer<Item> onBreak) {
|
||||||
- int i = this.processDurabilityChange(damage, level, player);
|
- int i = this.processDurabilityChange(damage, level, player);
|
||||||
|
- if (i != 0) {
|
||||||
+ public void hurtAndBreak(int damage, ServerLevel level, @Nullable LivingEntity player, Consumer<Item> onBreak) { // Paper - Add EntityDamageItemEvent
|
+ public void hurtAndBreak(int damage, ServerLevel level, @Nullable LivingEntity player, Consumer<Item> onBreak) { // Paper - Add EntityDamageItemEvent
|
||||||
+ // Paper start - add force boolean overload
|
+ // Paper start - add force boolean overload
|
||||||
+ this.hurtAndBreak(damage, level, player, onBreak, false);
|
+ this.hurtAndBreak(damage, level, player, onBreak, false);
|
||||||
|
@ -227,7 +228,7 @@
|
||||||
+ final int originalDamage = damage; // Paper - Expand PlayerItemDamageEvent
|
+ final int originalDamage = damage; // Paper - Expand PlayerItemDamageEvent
|
||||||
+ int i = this.processDurabilityChange(damage, level, player, force); // Paper
|
+ int i = this.processDurabilityChange(damage, level, player, force); // Paper
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
|
+ if (i > 0 && player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent - limit to positive damage and run for player
|
||||||
+ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i, originalDamage); // Paper - Add EntityDamageItemEvent
|
+ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i, originalDamage); // Paper - Add EntityDamageItemEvent
|
||||||
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
|
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
|
||||||
+
|
+
|
||||||
|
@ -240,7 +241,7 @@
|
||||||
+
|
+
|
||||||
+ i = event.getDamage();
|
+ i = event.getDamage();
|
||||||
+ // Paper start - Add EntityDamageItemEvent
|
+ // Paper start - Add EntityDamageItemEvent
|
||||||
+ } else if (player != null) {
|
+ } else if (i > 0 && player != null) {
|
||||||
+ io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i);
|
+ io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i);
|
||||||
+ if (!event.callEvent()) {
|
+ if (!event.callEvent()) {
|
||||||
+ return;
|
+ return;
|
||||||
|
@ -249,7 +250,7 @@
|
||||||
+ // Paper end - Add EntityDamageItemEvent
|
+ // Paper end - Add EntityDamageItemEvent
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
if (i != 0) {
|
+ if (i != 0) { // Paper - Add EntityDamageItemEvent - diff on change for above event ifs.
|
||||||
this.applyDamage(this.getDamageValue() + i, player, onBreak);
|
this.applyDamage(this.getDamageValue() + i, player, onBreak);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue