Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EntityType.java
1 package org.bukkit.entity;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
14 import org.bukkit.Location;
15 import org.bukkit.World;
16 
17 public enum EntityType {
18 
19  // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
20  /**
21  * An item resting on the ground.
22  * <p>
23  * Spawn with {@link World#dropItem(Location, ItemStack)} or {@link
24  * World#dropItemNaturally(Location, ItemStack)}
25  */
26  DROPPED_ITEM("Item", Item.class, 1, false),
27  /**
28  * An experience orb.
29  */
30  EXPERIENCE_ORB("XPOrb", ExperienceOrb.class, 2),
31  /**
32  * A leash attached to a fencepost.
33  */
34  LEASH_HITCH("LeashKnot", LeashHitch.class, 8),
35  /**
36  * A painting on a wall.
37  */
38  PAINTING("Painting", Painting.class, 9),
39  /**
40  * An arrow projectile; may get stuck in the ground.
41  */
42  ARROW("Arrow", Arrow.class, 10),
43  /**
44  * A flying snowball.
45  */
46  SNOWBALL("Snowball", Snowball.class, 11),
47  /**
48  * A flying large fireball, as thrown by a Ghast for example.
49  */
50  FIREBALL("Fireball", LargeFireball.class, 12),
51  /**
52  * A flying small fireball, such as thrown by a Blaze or player.
53  */
54  SMALL_FIREBALL("SmallFireball", SmallFireball.class, 13),
55  /**
56  * A flying ender pearl.
57  */
58  ENDER_PEARL("ThrownEnderpearl", EnderPearl.class, 14),
59  /**
60  * An ender eye signal.
61  */
62  ENDER_SIGNAL("EyeOfEnderSignal", EnderSignal.class, 15),
63  /**
64  * A flying experience bottle.
65  */
66  THROWN_EXP_BOTTLE("ThrownExpBottle", ThrownExpBottle.class, 17),
67  /**
68  * An item frame on a wall.
69  */
70  ITEM_FRAME("ItemFrame", ItemFrame.class, 18),
71  /**
72  * A flying wither skull projectile.
73  */
74  WITHER_SKULL("WitherSkull", WitherSkull.class, 19),
75  /**
76  * Primed TNT that is about to explode.
77  */
78  PRIMED_TNT("PrimedTnt", TNTPrimed.class, 20),
79  /**
80  * A block that is going to or is about to fall.
81  */
82  FALLING_BLOCK("FallingSand", FallingBlock.class, 21, false),
83  FIREWORK("FireworksRocketEntity", Firework.class, 22, false),
84  /**
85  * @see CommandMinecart
86  */
87  MINECART_COMMAND("MinecartCommandBlock", CommandMinecart.class, 40),
88  /**
89  * A placed boat.
90  */
91  BOAT("Boat", Boat.class, 41),
92  /**
93  * @see RideableMinecart
94  */
95  MINECART("MinecartRideable", RideableMinecart.class, 42),
96  /**
97  * @see StorageMinecart
98  */
99  MINECART_CHEST("MinecartChest", StorageMinecart.class, 43),
100  /**
101  * @see PoweredMinecart
102  */
103  MINECART_FURNACE("MinecartFurnace", PoweredMinecart.class, 44),
104  /**
105  * @see ExplosiveMinecart
106  */
107  MINECART_TNT("MinecartTNT", ExplosiveMinecart.class, 45),
108  /**
109  * @see HopperMinecart
110  */
111  MINECART_HOPPER("MinecartHopper", HopperMinecart.class, 46),
112  /**
113  * @see SpawnerMinecart
114  */
115  MINECART_MOB_SPAWNER("MinecartMobSpawner", SpawnerMinecart.class, 47),
116  CREEPER("Creeper", Creeper.class, 50),
117  SKELETON("Skeleton", Skeleton.class, 51),
118  SPIDER("Spider", Spider.class, 52),
119  GIANT("Giant", Giant.class, 53),
120  ZOMBIE("Zombie", Zombie.class, 54),
121  SLIME("Slime", Slime.class, 55),
122  GHAST("Ghast", Ghast.class, 56),
123  PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
124  ENDERMAN("Enderman", Enderman.class, 58),
125  CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
126  SILVERFISH("Silverfish", Silverfish.class, 60),
127  BLAZE("Blaze", Blaze.class, 61),
128  MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
129  ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
130  WITHER("WitherBoss", Wither.class, 64),
131  BAT("Bat", Bat.class, 65),
132  WITCH("Witch", Witch.class, 66),
133  PIG("Pig", Pig.class, 90),
134  SHEEP("Sheep", Sheep.class, 91),
135  COW("Cow", Cow.class, 92),
136  CHICKEN("Chicken", Chicken.class, 93),
137  SQUID("Squid", Squid.class, 94),
138  WOLF("Wolf", Wolf.class, 95),
139  MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
140  SNOWMAN("SnowMan", Snowman.class, 97),
141  OCELOT("Ozelot", Ocelot.class, 98),
142  IRON_GOLEM("VillagerGolem", IronGolem.class, 99),
143  HORSE("EntityHorse", Horse.class, 100),
144  VILLAGER("Villager", Villager.class, 120),
145  ENDER_CRYSTAL("EnderCrystal", EnderCrystal.class, 200),
146  // These don't have an entity ID in nms.EntityTypes.
147  /**
148  * A flying splash potion.
149  */
150  SPLASH_POTION(null, ThrownPotion.class, -1, false),
151  /**
152  * A flying chicken egg.
153  */
154  EGG(null, Egg.class, -1, false),
155  /**
156  * A fishing line and bobber.
157  */
158  FISHING_HOOK(null, Fish.class, -1, false),
159  /**
160  * A bolt of lightning.
161  * <p>
162  * Spawn with {@link World#strikeLightning(Location)}.
163  */
164  LIGHTNING(null, LightningStrike.class, -1, false),
165  WEATHER(null, Weather.class, -1, false),
166  PLAYER(null, Player.class, -1, false),
167  COMPLEX_PART(null, ComplexEntityPart.class, -1, false),
168  /**
169  * An unknown entity without an Entity Class
170  */
171  UNKNOWN(null, null, -1, false);
172 
173  private String name;
174  private Class<? extends Entity> clazz;
175  private short typeId;
176  private boolean independent, living;
177 
178  private static final Map<String, EntityType> NAME_MAP = new HashMap<String, EntityType>();
179  private static final Map<Short, EntityType> ID_MAP = new HashMap<Short, EntityType>();
180 
181  static {
182  for (EntityType type : values()) {
183  if (type.name != null) {
184  NAME_MAP.put(type.name.toLowerCase(), type);
185  }
186  if (type.typeId > 0) {
187  ID_MAP.put(type.typeId, type);
188  }
189  }
190  }
191 
192  private EntityType(String name, Class<? extends Entity> clazz, int typeId) {
193  this(name, clazz, typeId, true);
194  }
195 
196  private EntityType(String name, Class<? extends Entity> clazz, int typeId, boolean independent) {
197  this.name = name;
198  this.clazz = clazz;
199  this.typeId = (short) typeId;
200  this.independent = independent;
201  if (clazz != null) {
202  this.living = LivingEntity.class.isAssignableFrom(clazz);
203  }
204  }
205 
206  /**
207  *
208  * @deprecated Magic value
209  */
210  @Deprecated
211  public String getName() {
212  return name;
213  }
214 
215  public Class<? extends Entity> getEntityClass() {
216  return clazz;
217  }
218 
219  /**
220  *
221  * @deprecated Magic value
222  */
223  @Deprecated
224  public short getTypeId() {
225  return typeId;
226  }
227 
228  /**
229  *
230  * @deprecated Magic value
231  */
232  @Deprecated
233  public static EntityType fromName(String name) {
234  if (name == null) {
235  return null;
236  }
237  return NAME_MAP.get(name.toLowerCase());
238  }
239 
240  /**
241  *
242  * @deprecated Magic value
243  */
244  @Deprecated
245  public static EntityType fromId(int id) {
246  if (id > Short.MAX_VALUE) {
247  return null;
248  }
249  return ID_MAP.get((short) id);
250  }
251 
252  /**
253  * Some entities cannot be spawned using {@link
254  * World#spawnEntity(Location, EntityType)} or {@link
255  * World#spawn(Location, Class)}, usually because they require additional
256  * information in order to spawn.
257  *
258  * @return False if the entity type cannot be spawned
259  */
260  public boolean isSpawnable() {
261  return independent;
262  }
263 
264  public boolean isAlive() {
265  return living;
266  }
267 }
static EntityType fromId(int id)
static EntityType fromName(String name)