2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-06-27 09:46:57 +00:00
|
|
|
import org.bukkit.Location;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.Server;
|
2012-11-11 18:55:02 +00:00
|
|
|
import org.bukkit.World;
|
2013-01-09 00:40:52 +00:00
|
|
|
import org.bukkit.entity.Entity;
|
2012-03-01 16:33:09 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2012-11-11 17:04:16 +00:00
|
|
|
// Suffixes can be appended on the end of a mob name to make it plural
|
|
|
|
// Entities without a suffix, will default to 's'
|
2015-04-15 04:06:16 +00:00
|
|
|
public enum Mob {
|
|
|
|
CHICKEN("Chicken", Enemies.FRIENDLY, EntityType.CHICKEN),
|
|
|
|
COW("Cow", Enemies.FRIENDLY, EntityType.COW),
|
|
|
|
CREEPER("Creeper", Enemies.ENEMY, EntityType.CREEPER),
|
|
|
|
GHAST("Ghast", Enemies.ENEMY, EntityType.GHAST),
|
|
|
|
GIANT("Giant", Enemies.ENEMY, EntityType.GIANT),
|
|
|
|
HORSE("Horse", Enemies.FRIENDLY, EntityType.HORSE),
|
|
|
|
PIG("Pig", Enemies.FRIENDLY, EntityType.PIG),
|
|
|
|
PIGZOMB("PigZombie", Enemies.NEUTRAL, EntityType.PIG_ZOMBIE),
|
|
|
|
SHEEP("Sheep", Enemies.FRIENDLY, "", EntityType.SHEEP),
|
|
|
|
SKELETON("Skeleton", Enemies.ENEMY, EntityType.SKELETON),
|
|
|
|
SLIME("Slime", Enemies.ENEMY, EntityType.SLIME),
|
|
|
|
SPIDER("Spider", Enemies.ENEMY, EntityType.SPIDER),
|
|
|
|
SQUID("Squid", Enemies.FRIENDLY, EntityType.SQUID),
|
|
|
|
ZOMBIE("Zombie", Enemies.ENEMY, EntityType.ZOMBIE),
|
|
|
|
WOLF("Wolf", Enemies.NEUTRAL, "", EntityType.WOLF),
|
|
|
|
CAVESPIDER("CaveSpider", Enemies.ENEMY, EntityType.CAVE_SPIDER),
|
|
|
|
ENDERMAN("Enderman", Enemies.ENEMY, "", EntityType.ENDERMAN),
|
|
|
|
SILVERFISH("Silverfish", Enemies.ENEMY, "", EntityType.SILVERFISH),
|
|
|
|
ENDERDRAGON("EnderDragon", Enemies.ENEMY, EntityType.ENDER_DRAGON),
|
|
|
|
VILLAGER("Villager", Enemies.FRIENDLY, EntityType.VILLAGER),
|
|
|
|
BLAZE("Blaze", Enemies.ENEMY, EntityType.BLAZE),
|
|
|
|
MUSHROOMCOW("MushroomCow", Enemies.FRIENDLY, EntityType.MUSHROOM_COW),
|
|
|
|
MAGMACUBE("MagmaCube", Enemies.ENEMY, EntityType.MAGMA_CUBE),
|
|
|
|
SNOWMAN("Snowman", Enemies.FRIENDLY, "", EntityType.SNOWMAN),
|
|
|
|
OCELOT("Ocelot", Enemies.NEUTRAL, EntityType.OCELOT),
|
|
|
|
IRONGOLEM("IronGolem", Enemies.NEUTRAL, EntityType.IRON_GOLEM),
|
|
|
|
WITHER("Wither", Enemies.ENEMY, EntityType.WITHER),
|
|
|
|
BAT("Bat", Enemies.FRIENDLY, EntityType.BAT),
|
|
|
|
WITCH("Witch", Enemies.ENEMY, EntityType.WITCH),
|
|
|
|
BOAT("Boat", Enemies.NEUTRAL, EntityType.BOAT),
|
|
|
|
MINECART("Minecart", Enemies.NEUTRAL, EntityType.MINECART),
|
|
|
|
MINECART_CHEST("ChestMinecart", Enemies.NEUTRAL, EntityType.MINECART_CHEST),
|
|
|
|
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, EntityType.MINECART_FURNACE),
|
|
|
|
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, EntityType.MINECART_TNT),
|
|
|
|
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, EntityType.MINECART_HOPPER),
|
|
|
|
MINECART_MOB_SPAWNER("SpawnerMinecart", Enemies.NEUTRAL, EntityType.MINECART_MOB_SPAWNER),
|
|
|
|
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
|
2016-01-19 15:35:34 +00:00
|
|
|
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, "EXPERIENCE_ORB"),
|
|
|
|
ARMOR_STAND("ArmorStand", Enemies.NEUTRAL, "ARMOR_STAND"),
|
|
|
|
ENDERMITE("Endermite", Enemies.ENEMY, "ENDERMITE"),
|
|
|
|
GUARDIAN("Guardian", Enemies.ENEMY, "GUARDIAN"),
|
2016-11-20 16:03:56 +00:00
|
|
|
ELDER_GUARDIAN("ElderGuardian", Enemies.ENEMY, "ELDER_GUARDIAN"),
|
2016-03-01 03:52:02 +00:00
|
|
|
RABBIT("Rabbit", Enemies.FRIENDLY, "RABBIT"),
|
2016-06-10 02:19:59 +00:00
|
|
|
SHULKER("Shulker", Enemies.ENEMY, "SHULKER"),
|
2016-11-20 16:03:56 +00:00
|
|
|
POLAR_BEAR("PolarBear", Enemies.NEUTRAL, "POLAR_BEAR"),
|
|
|
|
WITHER_SKELETON("WitherSkeleton", Enemies.ENEMY, "WITHER_SKELETON"),
|
|
|
|
STRAY_SKELETON("StraySkeleton", Enemies.ENEMY, "STRAY"),
|
|
|
|
ZOMBIE_VILLAGER("ZombieVillager", Enemies.FRIENDLY, "ZOMBIE_VILLAGER"),
|
|
|
|
SKELETON_HORSE("SkeletonHorse", Enemies.FRIENDLY, "SKELETON_HORSE"),
|
|
|
|
ZOMBIE_HORSE("ZombieHorse", Enemies.FRIENDLY, "ZOMBIE_HORSE"),
|
|
|
|
DONKEY("Donkey", Enemies.FRIENDLY, "DONKEY"),
|
|
|
|
MULE("Mule", Enemies.FRIENDLY, "MULE"),
|
|
|
|
EVOKER("Evoker", Enemies.ENEMY, "EVOKER"),
|
|
|
|
VEX("Vex", Enemies.ENEMY, "VEX"),
|
|
|
|
VINDICATOR("Vindicator", Enemies.ENEMY, "VINDICATOR"),
|
|
|
|
LLAMA("Llama", Enemies.NEUTRAL, "LLAMA"),
|
|
|
|
HUSK("Husk", Enemies.ENEMY, "HUSK"),
|
2017-06-18 18:54:04 +00:00
|
|
|
ILLUSIONER("Illusioner", Enemies.ENEMY, "ILLUSIONER"),
|
2017-06-18 20:00:02 +00:00
|
|
|
PARROT("Parrot", Enemies.NEUTRAL, "PARROT"),
|
2016-11-20 16:03:56 +00:00
|
|
|
;
|
2015-04-16 13:52:29 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public static final Logger logger = Logger.getLogger("Essentials");
|
|
|
|
|
2015-06-03 20:11:56 +00:00
|
|
|
Mob(String n, Enemies en, String s, EntityType type) {
|
2015-04-15 04:06:16 +00:00
|
|
|
this.suffix = s;
|
|
|
|
this.name = n;
|
|
|
|
this.type = en;
|
|
|
|
this.bukkitType = type;
|
|
|
|
}
|
|
|
|
|
2015-06-03 20:11:56 +00:00
|
|
|
Mob(String n, Enemies en, EntityType type) {
|
2015-04-15 04:06:16 +00:00
|
|
|
this.name = n;
|
|
|
|
this.type = en;
|
|
|
|
this.bukkitType = type;
|
|
|
|
}
|
|
|
|
|
2016-01-19 15:35:34 +00:00
|
|
|
Mob(String n, Enemies en, String typeName) {
|
|
|
|
this.name = n;
|
|
|
|
this.type = en;
|
|
|
|
EntityType entityType;
|
|
|
|
try {
|
|
|
|
entityType = EntityType.valueOf(typeName);
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
entityType = null;
|
|
|
|
}
|
|
|
|
bukkitType = entityType;
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public String suffix = "s";
|
|
|
|
final public String name;
|
|
|
|
final public Enemies type;
|
|
|
|
final private EntityType bukkitType;
|
2016-01-19 15:35:34 +00:00
|
|
|
private static final Map<String, Mob> hashMap = new HashMap<>();
|
|
|
|
private static final Map<EntityType, Mob> bukkitMap = new HashMap<>();
|
2015-04-15 04:06:16 +00:00
|
|
|
|
|
|
|
static {
|
|
|
|
for (Mob mob : Mob.values()) {
|
|
|
|
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
|
2016-01-19 15:35:34 +00:00
|
|
|
if (mob.bukkitType != null) {
|
|
|
|
bukkitMap.put(mob.bukkitType, mob);
|
|
|
|
}
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Set<String> getMobList() {
|
|
|
|
return Collections.unmodifiableSet(hashMap.keySet());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Entity spawn(final World world, final Server server, final Location loc) throws MobException {
|
2015-06-03 20:11:56 +00:00
|
|
|
final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass());
|
2015-04-15 04:06:16 +00:00
|
|
|
if (entity == null) {
|
|
|
|
logger.log(Level.WARNING, tl("unableToSpawnMob"));
|
|
|
|
throw new MobException();
|
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum Enemies {
|
|
|
|
FRIENDLY("friendly"),
|
|
|
|
NEUTRAL("neutral"),
|
|
|
|
ENEMY("enemy");
|
|
|
|
|
2015-06-03 20:11:56 +00:00
|
|
|
Enemies(final String type) {
|
2015-04-15 04:06:16 +00:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected String type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityType getType() {
|
|
|
|
return bukkitType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Mob fromName(final String name) {
|
|
|
|
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Mob fromBukkitType(final EntityType type) {
|
|
|
|
return bukkitMap.get(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class MobException extends Exception {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|