From 6190a55cad21e1af680ab743a3257a0f0eba1682 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 11 Jan 2011 21:29:48 -0500 Subject: [PATCH] Added CREATURE_SPAWN event By: ss2man44 --- .../event/entity/CreatureSpawnEvent.java | 66 +++++++++++++++++++ .../bukkit/event/entity/EntityListener.java | 3 + .../bukkit/plugin/java/JavaPluginLoader.java | 5 ++ 3 files changed, 74 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.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 new file mode 100644 index 0000000000..b84b78cfd2 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java @@ -0,0 +1,66 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.MobType; +import org.bukkit.Location; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +/** + * Stores data for damage events + */ +public class CreatureSpawnEvent extends EntityEvent implements Cancellable { + + private Location location; + private boolean canceled; + private MobType mobtype; + + public CreatureSpawnEvent(Entity spawnee, MobType mobtype, Location loc) { + super(Event.Type.CREATURE_SPAWN, spawnee); + this.mobtype = mobtype; + this.location = loc; + } + + protected CreatureSpawnEvent(Event.Type type, Entity spawnee, MobType mobtype, Location loc) { + super(type, spawnee); + this.mobtype = mobtype; + this.location = loc; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the location at which the creature is spawning. + * @return The location at which the creature is spawning + */ + public Location getLocation() { + return location; + } + + /** + * Gets the type of creature being spawned. + * + * @return A CreatureType value detailing the type of creature being spawned + */ + public MobType getMobType() { + return mobtype; + } +} \ No newline at end of file diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java index fbc238b9ff..d4595957ec 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -9,6 +9,9 @@ public class EntityListener implements Listener { public EntityListener() { } + public void onCreatureSpawn(CreatureSpawnEvent event) { + } + public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { } diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 2c721eee32..e82b959057 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -358,6 +358,11 @@ public final class JavaPluginLoader implements PluginLoader { ((EntityListener)listener).onEntityTarget( (EntityTargetEvent)event ); } }; + case CREATURE_SPAWN: + return new EventExecutor() { public void execute( Listener listener, Event event ) { + ((EntityListener)listener).onCreatureSpawn( (CreatureSpawnEvent)event ); + } + }; // Vehicle Events case VEHICLE_CREATE: