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