From 21b8238e91c17dc7c9f8450fecb749f7a844596f Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 26 Dec 2018 08:00:00 +1100 Subject: [PATCH] Define EntitySpawnEvent By: Andy Shulman --- .../event/entity/CreatureSpawnEvent.java | 32 +----------- .../bukkit/event/entity/EntitySpawnEvent.java | 49 +++++++++++++++++++ .../bukkit/event/entity/ItemSpawnEvent.java | 41 +++------------- 3 files changed, 57 insertions(+), 65 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntitySpawnEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java index a5d64408a8..20d537734e 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java @@ -2,17 +2,13 @@ package org.bukkit.event.entity; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; /** * Called when a creature is spawned into a world. *

* If a Creature Spawn event is cancelled, the creature will not spawn. */ -public class CreatureSpawnEvent extends EntityEvent implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - private boolean canceled; +public class CreatureSpawnEvent extends EntitySpawnEvent { private final SpawnReason spawnReason; public CreatureSpawnEvent(final LivingEntity spawnee, final SpawnReason spawnReason) { @@ -20,28 +16,11 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { this.spawnReason = spawnReason; } - public boolean isCancelled() { - return canceled; - } - - public void setCancelled(boolean cancel) { - canceled = cancel; - } - @Override public LivingEntity getEntity() { return (LivingEntity) entity; } - /** - * Gets the location at which the creature is spawning. - * - * @return The location at which the creature is spawning - */ - public Location getLocation() { - return getEntity().getLocation(); - } - /** * Gets the reason for why the creature is being spawned. * @@ -52,15 +31,6 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { return spawnReason; } - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - /** * An enum to specify the type of spawning */ diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntitySpawnEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntitySpawnEvent.java new file mode 100644 index 0000000000..73ea074cd3 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntitySpawnEvent.java @@ -0,0 +1,49 @@ +package org.bukkit.event.entity; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Called when an entity is spawned into a world. + *

+ * If an Entity Spawn event is cancelled, the entity will not spawn. + */ +public class EntitySpawnEvent extends EntityEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean canceled; + + public EntitySpawnEvent(final Entity spawnee) { + super(spawnee); + } + + @Override + public boolean isCancelled() { + return canceled; + } + + @Override + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the location at which the entity is spawning. + * + * @return The location at which the entity is spawning + */ + public Location getLocation() { + return getEntity().getLocation(); + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java index bafd934a23..1435d3e4b2 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java @@ -1,51 +1,24 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Item; import org.bukkit.Location; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; +import org.bukkit.entity.Item; /** * Called when an item is spawned into a world */ -public class ItemSpawnEvent extends EntityEvent implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - private final Location location; - private boolean canceled; +public class ItemSpawnEvent extends EntitySpawnEvent { + @Deprecated public ItemSpawnEvent(final Item spawnee, final Location loc) { + this(spawnee); + } + + public ItemSpawnEvent(final Item spawnee) { super(spawnee); - this.location = loc; - } - - public boolean isCancelled() { - return canceled; - } - - public void setCancelled(boolean cancel) { - canceled = cancel; } @Override public Item getEntity() { return (Item) entity; } - - /** - * Gets the location at which the item is spawning. - * - * @return The location at which the item is spawning - */ - public Location getLocation() { - return location; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } }