diff --git a/patches/api/Entity-AddTo-RemoveFrom-World-Events.patch b/patches/api/Entity-AddTo-RemoveFrom-World-Events.patch index 6927e1ca1d..bbc34a5062 100644 --- a/patches/api/Entity-AddTo-RemoveFrom-World-Events.patch +++ b/patches/api/Entity-AddTo-RemoveFrom-World-Events.patch @@ -12,22 +12,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package com.destroystokyo.paper.event.entity; + ++import org.bukkit.World; +import org.bukkit.entity.Entity; -+import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.NotNull; + +/** -+ * Fired any time an entity is being added to the world for any reason. ++ * Fired any time an entity is being added to the world for any reason (including a chunk loading). + * + * Not to be confused with {@link org.bukkit.event.entity.CreatureSpawnEvent} -+ * This will fire anytime a chunk is reloaded too. + */ +public class EntityAddToWorldEvent extends EntityEvent { ++ @NotNull private final World world; + -+ public EntityAddToWorldEvent(@NotNull Entity entity) { ++ public EntityAddToWorldEvent(@NotNull Entity entity, @NotNull World world) { + super(entity); ++ this.world = world; ++ } ++ ++ /** ++ * @return The world that the entity is being added to ++ */ ++ @NotNull ++ public World getWorld() { ++ return world; + } + + private static final HandlerList handlers = new HandlerList(); @@ -50,19 +59,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package com.destroystokyo.paper.event.entity; + ++import org.bukkit.World; +import org.bukkit.entity.Entity; -+import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.NotNull; + +/** -+ * Fired any time an entity is being removed from a world for any reason ++ * Fired any time an entity is being removed from a world for any reason (including a chunk unloading). ++ * Note: The entity is updated prior to this event being called, as such, the entity's world may not be equal to {@link #getWorld()}. + */ +public class EntityRemoveFromWorldEvent extends EntityEvent { ++ @NotNull private final World world; + -+ public EntityRemoveFromWorldEvent(@NotNull Entity entity) { ++ public EntityRemoveFromWorldEvent(@NotNull Entity entity, @NotNull World world) { + super(entity); ++ this.world = world; ++ } ++ ++ /** ++ * @return The world that the entity is being removed from ++ */ ++ @NotNull ++ public World getWorld() { ++ return world; + } + + private static final HandlerList handlers = new HandlerList(); diff --git a/patches/server/Entity-AddTo-RemoveFrom-World-Events.patch b/patches/server/Entity-AddTo-RemoveFrom-World-Events.patch index 4e21acbb4f..177ed44ae7 100644 --- a/patches/server/Entity-AddTo-RemoveFrom-World-Events.patch +++ b/patches/server/Entity-AddTo-RemoveFrom-World-Events.patch @@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 entity.setOrigin(entity.getOriginVector().toLocation(getWorld())); } // Paper end -+ new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid ++ new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity(), ServerLevel.this.getWorld()).callEvent(); // Paper - fire while valid } public void onTrackingEnd(Entity entity) { @@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } // CraftBukkit end -+ new com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid ++ new com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent(entity.getBukkitEntity(), ServerLevel.this.getWorld()).callEvent(); // Paper - fire while valid } public void onSectionChange(Entity entity) {