Skip to content

Commit

Permalink
Fix totems negating incorrect item (PaperMC#11776)
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen1212055 authored Dec 23, 2024
1 parent f8bf600 commit 188124b
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,22 +668,25 @@
if (deathProtection != null) {
+ hand = interactionHand; // CraftBukkit
itemStack = itemInHand.copy();
- itemInHand.shrink(1);
+ // itemInHand.shrink(1); // CraftBukkit
break;
}
}

- if (itemStack != null) {
- if (this instanceof ServerPlayer serverPlayer) {
+ break;
+ }
+ }
+
+ org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
+ EntityResurrectEvent event = new EntityResurrectEvent((org.bukkit.entity.LivingEntity) this.getBukkitEntity(), handSlot);
+ event.setCancelled(itemStack == null);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ if (!itemStack.isEmpty() && itemStack != null) { // Paper - only reduce item if actual totem was found
+ itemStack.shrink(1);
+ if (!itemInHand.isEmpty() && itemStack != null) { // Paper - only reduce item if actual totem was found
itemInHand.shrink(1);
- break;
- }
- }
-
- if (itemStack != null) {
- if (this instanceof ServerPlayer serverPlayer) {
+ }
+ // Paper start - fix NPE when pre-cancelled EntityResurrectEvent is uncancelled
+ // restore the previous behavior in that case by defaulting to vanillas totem of undying efect
Expand Down

0 comments on commit 188124b

Please sign in to comment.