Success message on /spawner

Switch to use mob class.
This commit is contained in:
KHobbits 2011-08-19 12:06:35 +01:00
parent 2b48045a8f
commit a2f727bebc
10 changed files with 34 additions and 16 deletions

View File

@ -86,6 +86,9 @@ public enum Mob
final protected String type; final protected String type;
} }
public CreatureType getType () {
return bukkitType;
}
public static class MobException extends Exception public static class MobException extends Exception
{ {

View File

@ -483,4 +483,9 @@ public class Util
} }
return buf.toString(); return buf.toString();
} }
public static String capitalCase(String s)
{
return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1);
}
} }

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.Mob;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,6 +23,7 @@ public class Commandspawner extends EssentialsCommand
if (args.length < 1 || args[0].length() < 2) if (args.length < 1 || args[0].length() < 2)
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
//TODO: user.sendMessage("§7Mobs: Zombie PigZombie Skeleton Slime Chicken Pig Monster Spider Creeper Ghast Squid Giant Cow Sheep Wolf");
} }
final Block target = user.getTarget().getTargetBlock(); final Block target = user.getTarget().getTargetBlock();
@ -33,11 +35,18 @@ public class Commandspawner extends EssentialsCommand
charge(user); charge(user);
try try
{ {
String name = args[0].substring(0, 1).toUpperCase() + args[0].substring(1).toLowerCase(); String name = args[0];
if (name.equalsIgnoreCase("Pigzombie")) { name = name.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(name);
name = "PigZombie";
Mob mob = null;
mob = Mob.fromName(name);
if (mob == null)
{
user.sendMessage(Util.i18n("invalidMob"));
return;
} }
new CraftCreatureSpawner(target).setCreatureType(CreatureType.fromName(name)); new CraftCreatureSpawner(target).setCreatureType(mob.getType());
user.sendMessage(Util.format("setSpawner", mob.name));
} }
catch (Throwable ex) catch (Throwable ex)
{ {

View File

@ -40,7 +40,7 @@ public class Commandspawnmob extends EssentialsCommand
String[] mountparts = args[0].split(","); String[] mountparts = args[0].split(",");
String[] parts = mountparts[0].split(":"); String[] parts = mountparts[0].split(":");
String mobType = parts[0]; String mobType = parts[0];
mobType = mobType.equalsIgnoreCase("PigZombie") ? "PigZombie" : capitalCase(mobType); mobType = mobType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mobType);
String mobData = null; String mobData = null;
if (parts.length == 2) if (parts.length == 2)
{ {
@ -52,7 +52,7 @@ public class Commandspawnmob extends EssentialsCommand
{ {
parts = mountparts[1].split(":"); parts = mountparts[1].split(":");
mountType = parts[0]; mountType = parts[0];
mountType = mountType.equalsIgnoreCase("PigZombie") ? "PigZombie" : capitalCase(mountType); mountType = mountType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mountType);
if (parts.length == 2) if (parts.length == 2)
{ {
mountData = parts[1]; mountData = parts[1];
@ -186,11 +186,6 @@ public class Commandspawnmob extends EssentialsCommand
} }
} }
private String capitalCase(String s)
{
return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1);
}
private void changeMobData(String type, Entity spawned, String data, User user) throws Exception private void changeMobData(String type, Entity spawned, String data, User user) throws Exception
{ {
if ("Slime".equalsIgnoreCase(type)) if ("Slime".equalsIgnoreCase(type))
@ -210,8 +205,8 @@ public class Commandspawnmob extends EssentialsCommand
{ {
if (data.equalsIgnoreCase("random")) if (data.equalsIgnoreCase("random"))
{ {
Random rand = new Random(); Random rand = new Random();
((CraftSheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); ((CraftSheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
} }
else else
{ {

View File

@ -240,6 +240,7 @@ seconds = seconds
seenOffline = Player {0} is offline since {1} seenOffline = Player {0} is offline since {1}
seenOnline = Player {0} is online since {1} seenOnline = Player {0} is online since {1}
serverFull = Server is full serverFull = Server is full
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Malformed color. sheepMalformedColor = Malformed color.
shoutFormat = \u00a77[Shout]\u00a7f {0} shoutFormat = \u00a77[Shout]\u00a7f {0}
similarWarpExist = A warp with a similar name already exists. similarWarpExist = A warp with a similar name already exists.

View File

@ -240,6 +240,7 @@ seconds = sekunder
seenOffline = Spiller {0} er offline siden {1} seenOffline = Spiller {0} er offline siden {1}
seenOnline = Spiller {0} er online siden {1} seenOnline = Spiller {0} er online siden {1}
serverFull = Server er fuld serverFull = Server er fuld
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Misdannet farve. sheepMalformedColor = Misdannet farve.
shoutFormat = \u00a77[R\u00e5b]\u00a7f {0} shoutFormat = \u00a77[R\u00e5b]\u00a7f {0}
similarWarpExist = En warp med lignende tekst eksisterer allerede. similarWarpExist = En warp med lignende tekst eksisterer allerede.

View File

@ -238,6 +238,7 @@ seconds = Sekunden
seenOffline = Spieler {0} ist offline seit {1} seenOffline = Spieler {0} ist offline seit {1}
seenOnline = Spieler {0} ist online seit {1} seenOnline = Spieler {0} ist online seit {1}
serverFull = Server ist voll serverFull = Server ist voll
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Ung\u00fcltige Farbe. sheepMalformedColor = Ung\u00fcltige Farbe.
shoutFormat = \u00a77[Schrei]\u00a7f {0} shoutFormat = \u00a77[Schrei]\u00a7f {0}
similarWarpExist = Ein Warp-Punkt mit einem \u00e4hnlichen Namen existiert bereits. similarWarpExist = Ein Warp-Punkt mit einem \u00e4hnlichen Namen existiert bereits.

View File

@ -240,6 +240,7 @@ seconds = seconds
seenOffline = Player {0} is offline since {1} seenOffline = Player {0} is offline since {1}
seenOnline = Player {0} is online since {1} seenOnline = Player {0} is online since {1}
serverFull = Server is full serverFull = Server is full
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Malformed color. sheepMalformedColor = Malformed color.
shoutFormat = \u00a77[Shout]\u00a7f {0} shoutFormat = \u00a77[Shout]\u00a7f {0}
similarWarpExist = A warp with a similar name already exists. similarWarpExist = A warp with a similar name already exists.

View File

@ -238,6 +238,7 @@ seconds = secondes
seenOffline = Le joueur {0} est hors ligne depuis {1} seenOffline = Le joueur {0} est hors ligne depuis {1}
seenOnline = Le joueur {0} est en ligne depuis {1} seenOnline = Le joueur {0} est en ligne depuis {1}
serverFull = Le serveur est plein. serverFull = Le serveur est plein.
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Couleur mal form\u00e9e. sheepMalformedColor = Couleur mal form\u00e9e.
shoutFormat = \u00a77[Crie]\u00a7f {0} shoutFormat = \u00a77[Crie]\u00a7f {0}
similarWarpExist = Un warp avec un nom similaire existe d\u00e9j\u00e0. similarWarpExist = Un warp avec un nom similaire existe d\u00e9j\u00e0.

View File

@ -239,6 +239,7 @@ seconds = seconde
seenOffline = Speler {0} is offline vanaf {1} seenOffline = Speler {0} is offline vanaf {1}
seenOnline = Speler {0} is online vanaf {1} seenOnline = Speler {0} is online vanaf {1}
serverFull = Server is vol serverFull = Server is vol
setSpawner = Changed spawner type to {0}
sheepMalformedColor = Misvoormde kleur. sheepMalformedColor = Misvoormde kleur.
shoutFormat = \u00a77[Shout]\u00a7f {0} shoutFormat = \u00a77[Shout]\u00a7f {0}
similarWarpExist = Er bestaat al een warp met dezelfde naam. similarWarpExist = Er bestaat al een warp met dezelfde naam.