diff --git a/patches/api/Player-Entity-Tracking-Events.patch b/patches/api/Player-Entity-Tracking-Events.patch index a032bdf074..6164d2da9b 100644 --- a/patches/api/Player-Entity-Tracking-Events.patch +++ b/patches/api/Player-Entity-Tracking-Events.patch @@ -23,6 +23,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Is called when a {@link Player} tracks an {@link Entity}. + *
+ * If cancelled entity is not shown to the player and interaction in both directions is not possible. ++ *
++ * Adding or removing entities from the world at the point in time this event is called is completely ++ * unsupported and should be avoided. + */ +public class PlayerTrackEntityEvent extends PlayerEvent implements Cancellable { + @@ -82,6 +85,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +/** + * Is called when a {@link Player} untracks an {@link Entity}. ++ *
++ * Adding or removing entities from the world at the point in time this event is called is completely ++ * unsupported and should be avoided. + */ +public class PlayerUntrackEntityEvent extends PlayerEvent { + diff --git a/patches/server/Player-Entity-Tracking-Events.patch b/patches/server/Player-Entity-Tracking-Events.patch index 8bafa8b937..bf6899293b 100644 --- a/patches/server/Player-Entity-Tracking-Events.patch +++ b/patches/server/Player-Entity-Tracking-Events.patch @@ -19,11 +19,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end } } else if (this.seenBy.remove(player.connection)) { -+ // Paper start - entity tracking events -+ if (io.papermc.paper.event.player.PlayerUntrackEntityEvent.getHandlerList().getRegisteredListeners().length > 0) { -+ new io.papermc.paper.event.player.PlayerUntrackEntityEvent(player.getBukkitEntity(), this.entity.getBukkitEntity()).callEvent(); -+ } -+ // Paper end this.serverEntity.removePairing(player); - } +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S + public void startSeenByPlayer(ServerPlayer player) {} + +- public void stopSeenByPlayer(ServerPlayer player) {} ++ // Paper start - entity tracking events ++ public void stopSeenByPlayer(ServerPlayer player) { ++ // Since this event cannot be cancelled, we should call it here to catch all "un-tracks" ++ if (io.papermc.paper.event.player.PlayerUntrackEntityEvent.getHandlerList().getRegisteredListeners().length > 0) { ++ new io.papermc.paper.event.player.PlayerUntrackEntityEvent(player.getBukkitEntity(), this.getBukkitEntity()).callEvent(); ++ } ++ } ++ // Paper end + + public float rotate(Rotation rotation) { + float f = Mth.wrapDegrees(this.getYRot());