001 package org.bukkit.entity;
002
003 import java.util.EnumSet;
004 import java.util.HashMap;
005 import java.util.Map;
006
007 /**
008 * Represents a type of creature.
009 *
010 * @deprecated Use EntityType instead.
011 */
012 @Deprecated
013 public enum CreatureType {
014 // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
015 CREEPER("Creeper", Creeper.class, 50),
016 SKELETON("Skeleton", Skeleton.class, 51),
017 SPIDER("Spider", Spider.class, 52),
018 GIANT("Giant", Giant.class, 53),
019 ZOMBIE("Zombie", Zombie.class, 54),
020 SLIME("Slime", Slime.class, 55),
021 GHAST("Ghast", Ghast.class, 56),
022 PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
023 ENDERMAN("Enderman", Enderman.class, 58),
024 CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
025 SILVERFISH("Silverfish", Silverfish.class, 60),
026 BLAZE("Blaze", Blaze.class, 61),
027 MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
028 ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
029 PIG("Pig", Pig.class, 90),
030 SHEEP("Sheep", Sheep.class, 91),
031 COW("Cow", Cow.class, 92),
032 CHICKEN("Chicken", Chicken.class, 93),
033 SQUID("Squid", Squid.class, 94),
034 WOLF("Wolf", Wolf.class, 95),
035 MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
036 SNOWMAN("SnowMan", Snowman.class, 97),
037 VILLAGER("Villager", Villager.class, 120);
038
039 private String name;
040 private Class<? extends Entity> clazz;
041 private short typeId;
042
043 private static final Map<String, CreatureType> NAME_MAP = new HashMap<String, CreatureType>();
044 private static final Map<Short, CreatureType> ID_MAP = new HashMap<Short, CreatureType>();
045
046 static {
047 for (CreatureType type : EnumSet.allOf(CreatureType.class)) {
048 NAME_MAP.put(type.name, type);
049 if (type.typeId != 0) {
050 ID_MAP.put(type.typeId, type);
051 }
052 }
053 }
054
055 private CreatureType(String name, Class<? extends Entity> clazz, int typeId) {
056 this.name = name;
057 this.clazz = clazz;
058 this.typeId = (short) typeId;
059 }
060
061 public String getName() {
062 return name;
063 }
064
065 public Class<? extends Entity> getEntityClass() {
066 return clazz;
067 }
068
069 /**
070 *
071 * @deprecated Magic value
072 */
073 @Deprecated
074 public short getTypeId() {
075 return typeId;
076 }
077
078 public static CreatureType fromName(String name) {
079 return NAME_MAP.get(name);
080 }
081
082 /**
083 *
084 * @deprecated Magic value
085 */
086 @Deprecated
087 public static CreatureType fromId(int id) {
088 if (id > Short.MAX_VALUE) {
089 return null;
090 }
091 return ID_MAP.get((short) id);
092 }
093
094 @Deprecated
095 public EntityType toEntityType() {
096 return EntityType.fromName(getName());
097 }
098
099 public static CreatureType fromEntityType(EntityType creatureType) {
100 return fromName(creatureType.getName());
101 }
102 }