Skip to content

Commit 17d76ae

Browse files
authored
Correctly die when cancelling EntityResurrectEvent (#11785)
The existing logic in LivingEntity#checkTotemDeathProtection completes by checking whether the death protection component is null or not. In cases where the event was cancelled, the component needs to be nulled out to prevent the method from returning true, causing the player to properly die.
1 parent c768099 commit 17d76ae

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

paper-server/patches/features/0003-Entity-Activation-Range-2.0.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ index e7889c9c7b155db46730f5e168bb7fd3d1732a8c..334859c5ff7023c730513301cc11c983
533533
movement = this.maybeBackOffFromEdge(movement, type);
534534
Vec3 vec3 = this.collide(movement);
535535
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
536-
index a71a153a91de5a564b946091d8d3ccbb330e4b89..195e1151f7b2a32d6c4eb67edd1952e38f58b266 100644
536+
index ff513e8c87bf42be756e46f4dbfec8dda2b8cb60..239c443ddc9bacc08a39a8ef2ab17016a2480549 100644
537537
--- a/net/minecraft/world/entity/LivingEntity.java
538538
+++ b/net/minecraft/world/entity/LivingEntity.java
539-
@@ -3094,6 +3094,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
539+
@@ -3096,6 +3096,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
540540
return false;
541541
}
542542

paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@
654654
}
655655

656656
private boolean checkTotemDeathProtection(DamageSource damageSource) {
657-
@@ -1274,18 +_,37 @@
657+
@@ -1274,18 +_,39 @@
658658
ItemStack itemStack = null;
659659
DeathProtection deathProtection = null;
660660

@@ -673,12 +673,14 @@
673673
+ }
674674
+ }
675675
+
676-
+ org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
677-
+ EntityResurrectEvent event = new EntityResurrectEvent((org.bukkit.entity.LivingEntity) this.getBukkitEntity(), handSlot);
676+
+ final org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
677+
+ final EntityResurrectEvent event = new EntityResurrectEvent((org.bukkit.entity.LivingEntity) this.getBukkitEntity(), handSlot);
678678
+ event.setCancelled(itemStack == null);
679679
+ this.level().getCraftServer().getPluginManager().callEvent(event);
680-
+
681-
+ if (!event.isCancelled()) {
680+
+ if (event.isCancelled()) {
681+
+ // Set death protection to null as the event was cancelled. Prevent any attempt at ressurection.
682+
+ deathProtection = null;
683+
+ } else {
682684
+ if (!itemInHand.isEmpty() && itemStack != null) { // Paper - only reduce item if actual totem was found
683685
itemInHand.shrink(1);
684686
- break;
@@ -694,8 +696,8 @@
694696
+ deathProtection = DeathProtection.TOTEM_OF_UNDYING;
695697
+ }
696698
+ // Paper end - fix NPE when pre-cancelled EntityResurrectEvent is uncancelled
697-
+ if (itemStack != null && this instanceof ServerPlayer serverPlayer) {
698-
+ // CraftBukkit end
699+
+ if (itemStack != null && this instanceof final ServerPlayer serverPlayer) {
700+
+ // CraftBukkit end
699701
serverPlayer.awardStat(Stats.ITEM_USED.get(itemStack.getItem()));
700702
CriteriaTriggers.USED_TOTEM.trigger(serverPlayer, itemStack);
701703
this.gameEvent(GameEvent.ITEM_INTERACT_FINISH);

0 commit comments

Comments
 (0)