Add villager professions to /spawnmob

This commit is contained in:
KHobbits 2012-03-22 18:00:13 +00:00
parent 3d7d4a47d9
commit 165a76d492
2 changed files with 24 additions and 21 deletions

View File

@ -66,7 +66,7 @@ import org.yaml.snakeyaml.error.YAMLException;
public class Essentials extends JavaPlugin implements IEssentials
{
public static final int BUKKIT_VERSION = 2070;
public static final int BUKKIT_VERSION = 2098;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient ISettings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);

View File

@ -11,6 +11,8 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.material.Colorable;
public class Commandspawnmob extends EssentialsCommand
@ -199,7 +201,8 @@ public class Commandspawnmob extends EssentialsCommand
private void changeMobData(final EntityType type, final Entity spawned, String data, final User user) throws Exception
{
data = data.toLowerCase(Locale.ENGLISH);
if (type == EntityType.SLIME || type == EntityType.MAGMA_CUBE)
if (spawned instanceof Slime)
{
try
{
@ -210,32 +213,24 @@ public class Commandspawnmob extends EssentialsCommand
throw new Exception(_("slimeMalformedSize"), e);
}
}
if ((type == EntityType.SHEEP
|| type == EntityType.COW
|| type == EntityType.MUSHROOM_COW
|| type == EntityType.CHICKEN
|| type == EntityType.PIG
|| type == EntityType.VILLAGER
|| type == EntityType.OCELOT
|| type == EntityType.WOLF)
&& data.contains("baby"))
if (spawned instanceof Ageable && data.contains("baby"))
{
((Animals)spawned).setBaby();
((Ageable)spawned).setBaby();
return;
}
if (type == EntityType.SHEEP)
if (spawned instanceof Colorable)
{
final String color = data.toUpperCase(Locale.ENGLISH).replace("BABY", "");
try
{
if (color.equals("RANDOM"))
{
Random rand = new Random();
((Sheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
final Random rand = new Random();
((Colorable)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
}
else
{
((Sheep)spawned).setColor(DyeColor.valueOf(color));
((Colorable)spawned).setColor(DyeColor.valueOf(color));
}
}
catch (Exception e)
@ -243,9 +238,7 @@ public class Commandspawnmob extends EssentialsCommand
throw new Exception(_("sheepMalformedColor"), e);
}
}
if ((type == EntityType.WOLF
|| type == EntityType.OCELOT)
&& data.contains("tamed"))
if (spawned instanceof Tameable && data.contains("tamed"))
{
final Tameable tameable = ((Tameable)spawned);
tameable.setTamed(true);
@ -266,14 +259,24 @@ public class Commandspawnmob extends EssentialsCommand
{
((Ocelot)spawned).setCatType(Ocelot.Type.SIAMESE_CAT);
}
if (data.contains("red"))
else if (data.contains("red"))
{
((Ocelot)spawned).setCatType(Ocelot.Type.RED_CAT);
}
if (data.contains("black"))
else if (data.contains("black"))
{
((Ocelot)spawned).setCatType(Ocelot.Type.BLACK_CAT);
}
}
if (type == EntityType.VILLAGER)
{
for (Profession prof : Villager.Profession.values())
{
if (data.contains(prof.toString().toLowerCase(Locale.ENGLISH)))
{
((Villager)spawned).setProfession(prof);
}
}
}
}
}