From 7ad9895c2521adaf5686fba7591548fcaf2db9ae Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 28 Mar 2016 20:26:34 -0400 Subject: [PATCH] Entity AddTo/RemoveFrom World Events --- .../event/entity/EntityAddToWorldEvent.java | 44 +++++++++++++++++++ .../entity/EntityRemoveFromWorldEvent.java | 42 ++++++++++++++++++ .../event/entity/EntityRemoveEvent.java | 5 ++- 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java create mode 100644 paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java new file mode 100644 index 0000000000..11f8540a47 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java @@ -0,0 +1,44 @@ +package com.destroystokyo.paper.event.entity; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Fired any time an entity is being added to the world for any reason (including a chunk loading). + *

+ * Not to be confused with {@link CreatureSpawnEvent} + */ +@NullMarked +public class EntityAddToWorldEvent extends EntityEvent { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final World world; + + @ApiStatus.Internal + public EntityAddToWorldEvent(final Entity entity, final World world) { + super(entity); + this.world = world; + } + + /** + * @return The world that the entity is being added to + */ + public World getWorld() { + return this.world; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java new file mode 100644 index 0000000000..5ad5632d4d --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java @@ -0,0 +1,42 @@ +package com.destroystokyo.paper.event.entity; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * 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()}. + */ +@NullMarked +public class EntityRemoveFromWorldEvent extends EntityEvent { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final World world; + + @ApiStatus.Internal + public EntityRemoveFromWorldEvent(final Entity entity, final World world) { + super(entity); + this.world = world; + } + + /** + * @return The world that the entity is being removed from + */ + public World getWorld() { + return this.world; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java index e32df91d91..8ed5d1ccc4 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java @@ -1,5 +1,6 @@ package org.bukkit.event.entity; +import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent; import org.bukkit.entity.Entity; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.ApiStatus; @@ -11,8 +12,9 @@ import org.jetbrains.annotations.NotNull; * This event should only be used for monitoring. The result * of modifying the entity during or after this event is unspecified. * This event is not called for a {@link org.bukkit.entity.Player}. + * @deprecated use {@link EntityRemoveFromWorldEvent} instead */ -@ApiStatus.Experimental +@Deprecated(forRemoval = true) public class EntityRemoveEvent extends EntityEvent { private static final HandlerList handlers = new HandlerList(); @@ -112,5 +114,6 @@ public class EntityRemoveEvent extends EntityEvent { * When the chunk an entity is in gets unloaded. */ UNLOAD, + DISCARD } }