Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
CreatureSpawnEvent.java
1 package org.bukkit.event.entity;
2 
3 import org.bukkit.Location;
5 import org.bukkit.entity.Entity;
9 
10 /**
11  * Called when a creature is spawned into a world.
12  * <p>
13  * If a Creature Spawn event is cancelled, the creature will not spawn.
14  */
15 public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
16  private static final HandlerList handlers = new HandlerList();
17  private boolean canceled;
18  private final SpawnReason spawnReason;
19 
20  public CreatureSpawnEvent(final LivingEntity spawnee, final SpawnReason spawnReason) {
21  super(spawnee);
22  this.spawnReason = spawnReason;
23  }
24 
25  @Deprecated
26  public CreatureSpawnEvent(Entity spawnee, CreatureType type, Location loc, SpawnReason reason) {
27  super(spawnee);
28  spawnReason = reason;
29  }
30 
31  public boolean isCancelled() {
32  return canceled;
33  }
34 
35  public void setCancelled(boolean cancel) {
36  canceled = cancel;
37  }
38 
39  @Override
40  public LivingEntity getEntity() {
41  return (LivingEntity) entity;
42  }
43 
44  /**
45  * Gets the location at which the creature is spawning.
46  *
47  * @return The location at which the creature is spawning
48  */
49  public Location getLocation() {
50  return getEntity().getLocation();
51  }
52 
53  /**
54  * Gets the type of creature being spawned.
55  *
56  * @return A CreatureType value detailing the type of creature being
57  * spawned
58  * @deprecated In favour of {@link #getEntityType()}.
59  */
60  @Deprecated
62  return CreatureType.fromEntityType(getEntityType());
63  }
64 
65  /**
66  * Gets the reason for why the creature is being spawned.
67  *
68  * @return A SpawnReason value detailing the reason for the creature being
69  * spawned
70  */
72  return spawnReason;
73  }
74 
75  @Override
76  public HandlerList getHandlers() {
77  return handlers;
78  }
79 
80  public static HandlerList getHandlerList() {
81  return handlers;
82  }
83 
84  /**
85  * An enum to specify the type of spawning
86  */
87  public enum SpawnReason {
88 
89  /**
90  * When something spawns from natural means
91  */
93  /**
94  * When an entity spawns as a jockey of another entity (mostly spider
95  * jockeys)
96  */
98  /**
99  * When a creature spawns due to chunk generation
100  */
102  /**
103  * When a creature spawns from a spawner
104  */
106  /**
107  * When a creature spawns from an egg
108  */
110  /**
111  * When a creature spawns from a Spawner Egg
112  */
114  /**
115  * When a creature spawns because of a lightning strike
116  */
118  /**
119  * When a creature is spawned by a player that is sleeping
120  *
121  * @deprecated No longer used
122  */
123  @Deprecated
125  /**
126  * When a snowman is spawned by being built
127  */
129  /**
130  * When an iron golem is spawned by being built
131  */
133  /**
134  * When a wither boss is spawned by being built
135  */
137  /**
138  * When an iron golem is spawned to defend a village
139  */
141  /**
142  * When a zombie is spawned to invade a village
143  */
145  /**
146  * When an animal breeds to create a child
147  */
149  /**
150  * When a slime splits
151  */
153  /**
154  * When an entity calls for reinforcements
155  */
157  /**
158  * When a creature is spawned by nether portal
159  */
161  /**
162  * When a creature is spawned by a dispenser dispensing an egg
163  */
165  /**
166  * When a zombie infects a villager
167  */
169  /**
170  * When a villager is cured from infection
171  */
173  /**
174  * When an ocelot has a baby spawned along with them
175  */
177  /**
178  * When a silverfish spawns from a block
179  */
181  /**
182  * When an entity spawns as a mount of another entity (mostly chicken
183  * jockeys)
184  */
186  /**
187  * When a creature is spawned by plugins
188  */
190  /**
191  * When an entity is missing a SpawnReason
192  */
193  DEFAULT
194  }
195 }