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