001    package org.bukkit.entity;
002    
003    import java.util.HashMap;
004    import java.util.Map;
005    
006    import org.bukkit.entity.minecart.CommandMinecart;
007    import org.bukkit.entity.minecart.HopperMinecart;
008    import org.bukkit.entity.minecart.SpawnerMinecart;
009    import org.bukkit.entity.minecart.RideableMinecart;
010    import org.bukkit.entity.minecart.ExplosiveMinecart;
011    import org.bukkit.entity.minecart.PoweredMinecart;
012    import org.bukkit.entity.minecart.StorageMinecart;
013    import org.bukkit.inventory.ItemStack;
014    import org.bukkit.Location;
015    import org.bukkit.World;
016    
017    public enum EntityType {
018    
019        // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
020        /**
021         * An item resting on the ground.
022         * <p>
023         * Spawn with {@link World#dropItem(Location, ItemStack)} or {@link
024         * World#dropItemNaturally(Location, ItemStack)}
025         */
026        DROPPED_ITEM("Item", Item.class, 1, false),
027        /**
028         * An experience orb.
029         */
030        EXPERIENCE_ORB("XPOrb", ExperienceOrb.class, 2),
031        /**
032         * A leash attached to a fencepost.
033         */
034        LEASH_HITCH("LeashKnot", LeashHitch.class, 8),
035        /**
036         * A painting on a wall.
037         */
038        PAINTING("Painting", Painting.class, 9),
039        /**
040         * An arrow projectile; may get stuck in the ground.
041         */
042        ARROW("Arrow", Arrow.class, 10),
043        /**
044         * A flying snowball.
045         */
046        SNOWBALL("Snowball", Snowball.class, 11),
047        /**
048         * A flying large fireball, as thrown by a Ghast for example.
049         */
050        FIREBALL("Fireball", LargeFireball.class, 12),
051        /**
052         * A flying small fireball, such as thrown by a Blaze or player.
053         */
054        SMALL_FIREBALL("SmallFireball", SmallFireball.class, 13),
055        /**
056         * A flying ender pearl.
057         */
058        ENDER_PEARL("ThrownEnderpearl", EnderPearl.class, 14),
059        /**
060         * An ender eye signal.
061         */
062        ENDER_SIGNAL("EyeOfEnderSignal", EnderSignal.class, 15),
063        /**
064         * A flying experience bottle.
065         */
066        THROWN_EXP_BOTTLE("ThrownExpBottle", ThrownExpBottle.class, 17),
067        /**
068         * An item frame on a wall.
069         */
070        ITEM_FRAME("ItemFrame", ItemFrame.class, 18),
071        /**
072         * A flying wither skull projectile.
073         */
074        WITHER_SKULL("WitherSkull", WitherSkull.class, 19),
075        /**
076         * Primed TNT that is about to explode.
077         */
078        PRIMED_TNT("PrimedTnt", TNTPrimed.class, 20),
079        /**
080         * A block that is going to or is about to fall.
081         */
082        FALLING_BLOCK("FallingSand", FallingBlock.class, 21, false),
083        FIREWORK("FireworksRocketEntity", Firework.class, 22, false),
084        /**
085         * @see CommandMinecart
086         */
087        MINECART_COMMAND("MinecartCommandBlock", CommandMinecart.class, 40),
088        /**
089         * A placed boat.
090         */
091        BOAT("Boat", Boat.class, 41),
092        /**
093         * @see RideableMinecart
094         */
095        MINECART("MinecartRideable", RideableMinecart.class, 42),
096        /**
097         * @see StorageMinecart
098         */
099        MINECART_CHEST("MinecartChest", StorageMinecart.class, 43),
100        /**
101         * @see PoweredMinecart
102         */
103        MINECART_FURNACE("MinecartFurnace", PoweredMinecart.class, 44),
104        /**
105         * @see ExplosiveMinecart
106         */
107        MINECART_TNT("MinecartTNT", ExplosiveMinecart.class, 45),
108        /**
109         * @see HopperMinecart
110         */
111        MINECART_HOPPER("MinecartHopper", HopperMinecart.class, 46),
112        /**
113         * @see SpawnerMinecart
114         */
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.
147        /**
148         * A flying splash potion.
149         */
150        SPLASH_POTION(null, ThrownPotion.class, -1, false),
151        /**
152         * A flying chicken egg.
153         */
154        EGG(null, Egg.class, -1, false),
155        /**
156         * A fishing line and bobber.
157         */
158        FISHING_HOOK(null, Fish.class, -1, false),
159        /**
160         * A bolt of lightning.
161         * <p>
162         * Spawn with {@link World#strikeLightning(Location)}.
163         */
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),
168        /**
169         * An unknown entity without an Entity Class
170         */
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    
206        /**
207         *
208         * @deprecated Magic value
209         */
210        @Deprecated
211        public String getName() {
212            return name;
213        }
214    
215        public Class<? extends Entity> getEntityClass() {
216            return clazz;
217        }
218    
219        /**
220         *
221         * @deprecated Magic value
222         */
223        @Deprecated
224        public short getTypeId() {
225            return typeId;
226        }
227    
228        /**
229         *
230         * @deprecated Magic value
231         */
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    
240        /**
241         *
242         * @deprecated Magic value
243         */
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    
252        /**
253         * Some entities cannot be spawned using {@link
254         * World#spawnEntity(Location, EntityType)} or {@link
255         * World#spawn(Location, Class)}, usually because they require additional
256         * information in order to spawn.
257         *
258         * @return False if the entity type cannot be spawned
259         */
260        public boolean isSpawnable() {
261            return independent;
262        }
263    
264        public boolean isAlive() {
265            return living;
266        }
267    }