Bukkit  1.7.9-R0.2-63-gcb87f4e
 All Classes Namespaces Files Functions Variables Enumerator Pages
EntityType.java
Go to the documentation of this file.
1 package org.bukkit.entity;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
6 import org.bukkit.entity.minecart.CommandMinecart;
7 import org.bukkit.entity.minecart.HopperMinecart;
8 import org.bukkit.entity.minecart.SpawnerMinecart;
9 import org.bukkit.entity.minecart.RideableMinecart;
10 import org.bukkit.entity.minecart.ExplosiveMinecart;
11 import org.bukkit.entity.minecart.PoweredMinecart;
12 import org.bukkit.entity.minecart.StorageMinecart;
13 import org.bukkit.inventory.ItemStack;
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.
26  DROPPED_ITEM("Item", Item.class, 1, false),
30  EXPERIENCE_ORB("XPOrb", ExperienceOrb.class, 2),
34  LEASH_HITCH("LeashKnot", LeashHitch.class, 8),
38  PAINTING("Painting", Painting.class, 9),
42  ARROW("Arrow", Arrow.class, 10),
46  SNOWBALL("Snowball", Snowball.class, 11),
50  FIREBALL("Fireball", LargeFireball.class, 12),
54  SMALL_FIREBALL("SmallFireball", SmallFireball.class, 13),
58  ENDER_PEARL("ThrownEnderpearl", EnderPearl.class, 14),
62  ENDER_SIGNAL("EyeOfEnderSignal", EnderSignal.class, 15),
66  THROWN_EXP_BOTTLE("ThrownExpBottle", ThrownExpBottle.class, 17),
70  ITEM_FRAME("ItemFrame", ItemFrame.class, 18),
74  WITHER_SKULL("WitherSkull", WitherSkull.class, 19),
78  PRIMED_TNT("PrimedTnt", TNTPrimed.class, 20),
82  FALLING_BLOCK("FallingSand", FallingBlock.class, 21, false),
83  FIREWORK("FireworksRocketEntity", Firework.class, 22, false),
87  MINECART_COMMAND("MinecartCommandBlock", CommandMinecart.class, 40),
91  BOAT("Boat", Boat.class, 41),
95  MINECART("MinecartRideable", RideableMinecart.class, 42),
99  MINECART_CHEST("MinecartChest", StorageMinecart.class, 43),
103  MINECART_FURNACE("MinecartFurnace", PoweredMinecart.class, 44),
107  MINECART_TNT("MinecartTNT", ExplosiveMinecart.class, 45),
111  MINECART_HOPPER("MinecartHopper", HopperMinecart.class, 46),
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.
150  SPLASH_POTION(null, ThrownPotion.class, -1, false),
154  EGG(null, Egg.class, -1, false),
158  FISHING_HOOK(null, Fish.class, -1, false),
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),
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 
210  @Deprecated
211  public String getName() {
212  return name;
213  }
214 
215  public Class<? extends Entity> getEntityClass() {
216  return clazz;
217  }
218 
223  @Deprecated
224  public short getTypeId() {
225  return typeId;
226  }
227 
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 
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 
260  public boolean isSpawnable() {
261  return independent;
262  }
263 
264  public boolean isAlive() {
265  return living;
266  }
267 }