Bukkit  1.5.2-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
CreatureType.java
Go to the documentation of this file.
1 package org.bukkit.entity;
2 
3 import java.util.EnumSet;
4 import java.util.HashMap;
5 import java.util.Map;
6 
11 @Deprecated
12 public enum CreatureType {
13  // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
14  CREEPER("Creeper", Creeper.class, 50),
15  SKELETON("Skeleton", Skeleton.class, 51),
16  SPIDER("Spider", Spider.class, 52),
17  GIANT("Giant", Giant.class, 53),
18  ZOMBIE("Zombie", Zombie.class, 54),
19  SLIME("Slime", Slime.class, 55),
20  GHAST("Ghast", Ghast.class, 56),
21  PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
22  ENDERMAN("Enderman", Enderman.class, 58),
23  CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
24  SILVERFISH("Silverfish", Silverfish.class, 60),
25  BLAZE("Blaze", Blaze.class, 61),
26  MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
27  ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
28  PIG("Pig", Pig.class, 90),
29  SHEEP("Sheep", Sheep.class, 91),
30  COW("Cow", Cow.class, 92),
31  CHICKEN("Chicken", Chicken.class, 93),
32  SQUID("Squid", Squid.class, 94),
33  WOLF("Wolf", Wolf.class, 95),
34  MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
35  SNOWMAN("SnowMan", Snowman.class, 97),
36  VILLAGER("Villager", Villager.class, 120);
37 
38  private String name;
39  private Class<? extends Entity> clazz;
40  private short typeId;
41 
42  private static final Map<String, CreatureType> NAME_MAP = new HashMap<String, CreatureType>();
43  private static final Map<Short, CreatureType> ID_MAP = new HashMap<Short, CreatureType>();
44 
45  static {
46  for (CreatureType type : EnumSet.allOf(CreatureType.class)) {
47  NAME_MAP.put(type.name, type);
48  if (type.typeId != 0) {
49  ID_MAP.put(type.typeId, type);
50  }
51  }
52  }
53 
54  private CreatureType(String name, Class<? extends Entity> clazz, int typeId) {
55  this.name = name;
56  this.clazz = clazz;
57  this.typeId = (short) typeId;
58  }
59 
60  public String getName() {
61  return name;
62  }
63 
64  public Class<? extends Entity> getEntityClass() {
65  return clazz;
66  }
67 
68  public short getTypeId() {
69  return typeId;
70  }
71 
72  public static CreatureType fromName(String name) {
73  return NAME_MAP.get(name);
74  }
75 
76  public static CreatureType fromId(int id) {
77  if (id > Short.MAX_VALUE) {
78  return null;
79  }
80  return ID_MAP.get((short) id);
81  }
82 
83  @Deprecated
85  return EntityType.fromName(getName());
86  }
87 
88  public static CreatureType fromEntityType(EntityType creatureType) {
89  return fromName(creatureType.getName());
90  }
91 }