TF-EssentialsX/Essentials/src/com/earth2me/essentials/Mob.java

122 lines
3.6 KiB
Java
Raw Normal View History

package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
2011-06-27 09:46:57 +00:00
import org.bukkit.Location;
import org.bukkit.Server;
2012-03-01 16:33:09 +00:00
import org.bukkit.entity.EntityType;
2011-06-27 09:46:57 +00:00
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
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'
public enum Mob
{
2012-03-01 16:33:09 +00:00
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),
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),
2012-03-01 23:06:57 +00:00
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),
2012-10-20 09:24:18 +00:00
WITCH("Witch", Enemies.ENEMY, EntityType.WITCH);
public static final Logger logger = Logger.getLogger("Minecraft");
2012-03-01 16:33:09 +00:00
private Mob(String n, Enemies en, String s, EntityType type)
{
2011-06-27 09:46:57 +00:00
this.suffix = s;
this.name = n;
this.type = en;
2011-06-27 09:46:57 +00:00
this.bukkitType = type;
}
2012-03-01 16:33:09 +00:00
private Mob(String n, Enemies en, EntityType type)
{
this.name = n;
this.type = en;
2011-06-27 09:46:57 +00:00
this.bukkitType = type;
}
2011-06-27 09:46:57 +00:00
public String suffix = "s";
final public String name;
final public Enemies type;
2012-03-01 16:33:09 +00:00
final private EntityType bukkitType;
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
static
{
for (Mob mob : Mob.values())
{
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
}
}
public static Set<String> getMobList() {
2012-03-04 21:43:24 +00:00
return Collections.unmodifiableSet(hashMap.keySet());
}
2011-06-27 09:46:57 +00:00
public LivingEntity spawn(final Player player, final Server server, final Location loc) throws MobException
{
final LivingEntity entity = player.getWorld().spawn(loc, (Class<? extends LivingEntity>)this.bukkitType.getEntityClass());
2011-06-27 09:46:57 +00:00
if (entity == null)
{
logger.log(Level.WARNING, _("unableToSpawnMob"));
2011-06-27 09:46:57 +00:00
throw new MobException();
}
2011-06-27 09:46:57 +00:00
return entity;
}
public enum Enemies
{
FRIENDLY("friendly"),
NEUTRAL("neutral"),
ENEMY("enemy");
2011-11-20 13:33:17 +00:00
private Enemies(final String type)
{
2011-11-20 13:33:17 +00:00
this.type = type;
}
2011-06-27 09:46:57 +00:00
final protected String type;
}
2012-03-01 16:33:09 +00:00
public EntityType getType()
2011-11-20 13:33:17 +00:00
{
return bukkitType;
}
2011-11-20 13:33:17 +00:00
public static Mob fromName(final String name)
{
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
}
2011-11-20 13:33:17 +00:00
public static class MobException extends Exception
{
2011-11-20 13:33:17 +00:00
private static final long serialVersionUID = 1L;
}
}