Bukkit  1.6.4-R2.0
 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.HopperMinecart;
7 import org.bukkit.entity.minecart.SpawnerMinecart;
8 import org.bukkit.entity.minecart.RideableMinecart;
9 import org.bukkit.entity.minecart.ExplosiveMinecart;
10 import org.bukkit.entity.minecart.PoweredMinecart;
11 import org.bukkit.entity.minecart.StorageMinecart;
12 import org.bukkit.inventory.ItemStack;
13 import org.bukkit.Location;
14 import org.bukkit.World;
15 
16 public enum EntityType {
17 
18  // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
25  DROPPED_ITEM("Item", Item.class, 1, false),
29  EXPERIENCE_ORB("XPOrb", ExperienceOrb.class, 2),
33  LEASH_HITCH("LeashKnot", LeashHitch.class, 8),
37  PAINTING("Painting", Painting.class, 9),
41  ARROW("Arrow", Arrow.class, 10),
45  SNOWBALL("Snowball", Snowball.class, 11),
49  FIREBALL("Fireball", LargeFireball.class, 12),
53  SMALL_FIREBALL("SmallFireball", SmallFireball.class, 13),
57  ENDER_PEARL("ThrownEnderpearl", EnderPearl.class, 14),
61  ENDER_SIGNAL("EyeOfEnderSignal", EnderSignal.class, 15),
65  THROWN_EXP_BOTTLE("ThrownExpBottle", ThrownExpBottle.class, 17),
69  ITEM_FRAME("ItemFrame", ItemFrame.class, 18),
73  WITHER_SKULL("WitherSkull", WitherSkull.class, 19),
77  PRIMED_TNT("PrimedTnt", TNTPrimed.class, 20),
81  FALLING_BLOCK("FallingSand", FallingBlock.class, 21, false),
82  FIREWORK("FireworksRocketEntity", Firework.class, 22, false),
86  BOAT("Boat", Boat.class, 41),
90  MINECART("MinecartRideable", RideableMinecart.class, 42),
94  MINECART_CHEST("MinecartChest", StorageMinecart.class, 43),
98  MINECART_FURNACE("MinecartFurnace", PoweredMinecart.class, 44),
102  MINECART_TNT("MinecartTNT", ExplosiveMinecart.class, 45),
106  MINECART_HOPPER("MinecartHopper", HopperMinecart.class, 46),
110  MINECART_MOB_SPAWNER("MinecartMobSpawner", SpawnerMinecart.class, 47),
111  CREEPER("Creeper", Creeper.class, 50),
112  SKELETON("Skeleton", Skeleton.class, 51),
113  SPIDER("Spider", Spider.class, 52),
114  GIANT("Giant", Giant.class, 53),
115  ZOMBIE("Zombie", Zombie.class, 54),
116  SLIME("Slime", Slime.class, 55),
117  GHAST("Ghast", Ghast.class, 56),
118  PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
119  ENDERMAN("Enderman", Enderman.class, 58),
120  CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
121  SILVERFISH("Silverfish", Silverfish.class, 60),
122  BLAZE("Blaze", Blaze.class, 61),
123  MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
124  ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
125  WITHER("WitherBoss", Wither.class, 64),
126  BAT("Bat", Bat.class, 65),
127  WITCH("Witch", Witch.class, 66),
128  PIG("Pig", Pig.class, 90),
129  SHEEP("Sheep", Sheep.class, 91),
130  COW("Cow", Cow.class, 92),
131  CHICKEN("Chicken", Chicken.class, 93),
132  SQUID("Squid", Squid.class, 94),
133  WOLF("Wolf", Wolf.class, 95),
134  MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
135  SNOWMAN("SnowMan", Snowman.class, 97),
136  OCELOT("Ozelot", Ocelot.class, 98),
137  IRON_GOLEM("VillagerGolem", IronGolem.class, 99),
138  HORSE("EntityHorse", Horse.class, 100),
139  VILLAGER("Villager", Villager.class, 120),
140  ENDER_CRYSTAL("EnderCrystal", EnderCrystal.class, 200),
141  // These don't have an entity ID in nms.EntityTypes.
145  SPLASH_POTION(null, ThrownPotion.class, -1, false),
149  EGG(null, Egg.class, -1, false),
153  FISHING_HOOK(null, Fish.class, -1, false),
159  LIGHTNING(null, LightningStrike.class, -1, false),
160  WEATHER(null, Weather.class, -1, false),
161  PLAYER(null, Player.class, -1, false),
162  COMPLEX_PART(null, ComplexEntityPart.class, -1, false),
166  UNKNOWN(null, null, -1, false);
167 
168  private String name;
169  private Class<? extends Entity> clazz;
170  private short typeId;
171  private boolean independent, living;
172 
173  private static final Map<String, EntityType> NAME_MAP = new HashMap<String, EntityType>();
174  private static final Map<Short, EntityType> ID_MAP = new HashMap<Short, EntityType>();
175 
176  static {
177  for (EntityType type : values()) {
178  if (type.name != null) {
179  NAME_MAP.put(type.name.toLowerCase(), type);
180  }
181  if (type.typeId > 0) {
182  ID_MAP.put(type.typeId, type);
183  }
184  }
185  }
186 
187  private EntityType(String name, Class<? extends Entity> clazz, int typeId) {
188  this(name, clazz, typeId, true);
189  }
190 
191  private EntityType(String name, Class<? extends Entity> clazz, int typeId, boolean independent) {
192  this.name = name;
193  this.clazz = clazz;
194  this.typeId = (short) typeId;
195  this.independent = independent;
196  if (clazz != null) {
197  this.living = LivingEntity.class.isAssignableFrom(clazz);
198  }
199  }
200 
205  @Deprecated
206  public String getName() {
207  return name;
208  }
209 
210  public Class<? extends Entity> getEntityClass() {
211  return clazz;
212  }
213 
218  @Deprecated
219  public short getTypeId() {
220  return typeId;
221  }
222 
227  @Deprecated
228  public static EntityType fromName(String name) {
229  if (name == null) {
230  return null;
231  }
232  return NAME_MAP.get(name.toLowerCase());
233  }
234 
239  @Deprecated
240  public static EntityType fromId(int id) {
241  if (id > Short.MAX_VALUE) {
242  return null;
243  }
244  return ID_MAP.get((short) id);
245  }
246 
254  public boolean isSpawnable() {
255  return independent;
256  }
257 
258  public boolean isAlive() {
259  return living;
260  }
261 }