From fcfa05f48261555b1ee0b998fff744a94b1ace9a Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 21 Jun 2011 15:58:41 -0400 Subject: [PATCH] Added SpawnReasons to CreatureSpawn events. Thanks winsock! --- .../event/entity/CreatureSpawnEvent.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java index 06621a00..5761b87a 100644 --- a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java +++ b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java @@ -13,11 +13,13 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { private Location location; private boolean canceled; private CreatureType creatureType; + private SpawnReason spawnReason; - public CreatureSpawnEvent(Entity spawnee, CreatureType mobtype, Location loc) { + public CreatureSpawnEvent(Entity spawnee, CreatureType mobtype, Location loc, SpawnReason spawnReason) { super(Type.CREATURE_SPAWN, spawnee); this.creatureType = mobtype; this.location = loc; + this.spawnReason = spawnReason; } /** @@ -56,4 +58,44 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { public CreatureType getCreatureType() { return creatureType; } + + /** + * Gets the reason for why the creature is being spawned. + * + * @return A SpawnReason value detailing the reason for the creature being spawned + */ + public SpawnReason getSpawnReason() { + return spawnReason; + } + + /** + * An enum to specify the type of spawning + */ + public enum SpawnReason { + + /** + * When something spawns from natural means + */ + NATURAL, + /** + * When a creature spawns from a spawner + */ + SPAWNER, + /** + * When a creature spawns from an egg + */ + EGG, + /** + * When a creature spawns because of a lightning strike + */ + LIGHTNING, + /** + * When a creature is spawned by a player that is sleeping + */ + BED, + /** + * When a creature is manually spawned + */ + CUSTOM + } }