Make /spawner errors more descriptive.

This commit is contained in:
KHobbits 2012-03-15 04:41:56 +00:00
parent d0d0117411
commit 45cf2ae960

View file

@ -1,10 +1,7 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.*;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Mob;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -34,34 +31,34 @@ public class Commandspawner extends EssentialsCommand
throw new Exception(_("mobSpawnTarget")); throw new Exception(_("mobSpawnTarget"));
} }
try
{
String name = args[0]; String name = args[0];
Mob mob = null; Mob mob = null;
mob = Mob.fromName(name); mob = Mob.fromName(name);
if (mob == null) if (mob == null)
{ {
user.sendMessage(_("invalidMob")); throw new Exception(_("invalidMob"));
return;
} }
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH)))
{ {
throw new Exception(_("unableToSpawnMob")); throw new Exception(_("disabledToSpawnMob"));
} }
if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH)))
{ {
throw new Exception(_("unableToSpawnMob")); throw new Exception(_("noPermToSpawnMob"));
} }
final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess); final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
charge.isAffordableFor(user); charge.isAffordableFor(user);
try
{
((CreatureSpawner)target.getBlock().getState()).setSpawnedType(mob.getType()); ((CreatureSpawner)target.getBlock().getState()).setSpawnedType(mob.getType());
charge.charge(user);
user.sendMessage(_("setSpawner", mob.name));
} }
catch (Throwable ex) catch (Throwable ex)
{ {
throw new Exception(_("mobSpawnError"), ex); throw new Exception(_("mobSpawnError"), ex);
} }
charge.charge(user);
user.sendMessage(_("setSpawner", mob.name));
} }
} }