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