Correctly charge for the use of commands.

We now first test, if the user could pay it, do the stuff and then charge him. If the command throws an exception, the user will not be charged.
This commit is contained in:
snowleo 2011-08-27 23:14:49 +02:00
parent 610a713997
commit 6427a93d14
66 changed files with 40 additions and 347 deletions

View File

@ -15,8 +15,6 @@ public class Commandafk extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
if (args.length > 0 && user.isAuthorized("essentials.afk.others"))
{
User afkUser = ess.getUser(ess.getServer().matchPlayer(args[0]));

View File

@ -17,7 +17,6 @@ public class Commandantioch extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
charge(user);
ess.broadcastMessage(user.getName(), "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,");
ess.broadcastMessage(user.getName(), "who being naughty in My sight, shall snuff it.");

View File

@ -19,9 +19,8 @@ public class Commandbackup extends EssentialsCommand
Backup backup = ess.getBackup();
if (backup == null)
{
return;
throw new Exception();
}
charge(sender);
backup.run();
sender.sendMessage(Util.i18n("backupStarted"));
}

View File

@ -26,7 +26,6 @@ public class Commandbalance extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
double bal = (args.length < 1
|| !(user.isAuthorized("essentials.balance.others")
|| user.isAuthorized("essentials.balance.other"))

View File

@ -41,12 +41,11 @@ public class Commandbigtree extends EssentialsCommand
final boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree);
if (success)
{
charge(user);
user.sendMessage(Util.i18n("bigTreeSuccess"));
}
else
{
user.sendMessage(Util.i18n("bigTreeFailure"));
throw new Exception(Util.i18n("bigTreeFailure"));
}
}
}

View File

@ -22,7 +22,6 @@ public class Commandbroadcast extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(sender);
ess.broadcastMessage(sender instanceof Player ? ((Player)sender).getName() : Console.NAME,
Util.format("broadcast", getFinalArg(args, 0)));
}

View File

@ -21,7 +21,6 @@ public class Commandburn extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(sender);
for (Player p : server.matchPlayer(args[0]))
{
p.setFireTicks(Integer.parseInt(args[1]) * 20);

View File

@ -27,7 +27,6 @@ public class Commandclearinventory extends EssentialsCommand
if (!online.isEmpty())
{
charge(user);
for (Player p : online)
{
p.getInventory().clear();
@ -42,7 +41,6 @@ public class Commandclearinventory extends EssentialsCommand
Player p = server.getPlayer(args[0]);
if (p != null)
{
charge(user);
p.getInventory().clear();
user.sendMessage(Util.format("inventoryClearedOthers", p.getDisplayName()));
}
@ -54,7 +52,6 @@ public class Commandclearinventory extends EssentialsCommand
}
else
{
charge(user);
user.getInventory().clear();
user.sendMessage(Util.i18n("inventoryCleared"));
}

View File

@ -102,7 +102,6 @@ public class Commandessentials extends EssentialsCommand
return;
}
ess.reload();
charge(sender);
sender.sendMessage(Util.format("essentialsReload", ess.getDescription().getVersion()));
}

View File

@ -30,7 +30,6 @@ public class Commandext extends EssentialsCommand
{
if (args.length < 1)
{
charge(user);
user.setFireTicks(0);
user.sendMessage(Util.i18n("extinguish"));
return;
@ -43,7 +42,6 @@ public class Commandext extends EssentialsCommand
{
for (Player p : server.matchPlayer(name))
{
charge(sender);
p.setFireTicks(0);
sender.sendMessage(Util.format("extinguishOthers", p.getDisplayName()));
}

View File

@ -17,7 +17,6 @@ public class Commandfireball extends EssentialsCommand
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
charge(user);
final Vector direction = user.getEyeLocation().getDirection().multiply(2);
user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Fireball.class);
}

View File

@ -16,7 +16,6 @@ public class Commandgc extends EssentialsCommand
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
charge(sender);
sender.sendMessage(Util.format("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)));
sender.sendMessage(Util.format("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
sender.sendMessage(Util.format("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)));

View File

@ -15,7 +15,6 @@ public class Commandgetpos extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
Location coords = user.getLocation();
user.sendMessage("§7X: " + coords.getBlockX() + " (-North <-> +South)");
user.sendMessage("§7Y: " + coords.getBlockY() + " (+Up <-> -Down)");

View File

@ -36,8 +36,7 @@ public class Commandgive extends EssentialsCommand
: (!ess.getUser(sender).isAuthorized("essentials.itemspawn.exempt")
&& !ess.getUser(sender).canSpawnItem(stack.getTypeId()))))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
return;
throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
}
if (args.length > 2 && Integer.parseInt(args[2]) > 0)
{
@ -46,13 +45,11 @@ public class Commandgive extends EssentialsCommand
if (stack.getType() == Material.AIR)
{
sender.sendMessage(ChatColor.RED + "You can't give air.");
return;
throw new Exception(ChatColor.RED + "You can't give air.");
}
User giveTo = getPlayer(server, args, 0);
String itemName = stack.getType().toString().toLowerCase().replace('_', ' ');
charge(sender);
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
giveTo.getInventory().addItem(stack);
giveTo.updateInventory();

View File

@ -28,7 +28,6 @@ public class Commandgod extends EssentialsCommand
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
if (args.length > 0 && user.isAuthorized("essentials.god.others"))
{
godOtherPlayers(server, user, args[0]);

View File

@ -25,7 +25,6 @@ public class Commandheal extends EssentialsCommand
{
user.healCooldown();
}
charge(user);
healOtherPlayers(server, user, args[0]);
return;
}
@ -34,7 +33,6 @@ public class Commandheal extends EssentialsCommand
{
user.healCooldown();
}
charge(user);
user.setHealth(20);
user.sendMessage(Util.i18n("heal"));
}

View File

@ -22,7 +22,6 @@ public class Commandhelpop extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(user);
final String message = Util.format("helpOp", user.getDisplayName(), getFinalArg(args, 0));
logger.log(Level.INFO, message);
for (Player p : server.getOnlinePlayers())

View File

@ -68,9 +68,8 @@ public class Commandinfo extends EssentialsCommand
}
else
{
sender.sendMessage(Util.i18n("infoFileDoesNotExist"));
file.createNewFile();
return;
throw new Exception(Util.i18n("infoFileDoesNotExist"));
}
if (bookmarks.isEmpty())
@ -88,7 +87,6 @@ public class Commandinfo extends EssentialsCommand
int start = (page - 1) * 9;
int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
charge(sender);
sender.sendMessage(Util.format("infoPages", page, pages ));
for (int i = start; i < lines.size() && i < start + 9; i++)
{
@ -140,7 +138,6 @@ public class Commandinfo extends EssentialsCommand
}
int pages = end / 9 + (end % 9 > 0 ? 1 : 0);
charge(sender);
sender.sendMessage(Util.format("infoPages", page, pages ));
for (int i = start; i < end && i < start + 9; i++)
{
@ -182,7 +179,6 @@ public class Commandinfo extends EssentialsCommand
int page = chapterpage + 1;
int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0);
charge(sender);
sender.sendMessage(Util.format("infoChapterPages", pageStr, page , pages));
for (int i = start; i < chapterend && i < start + 9; i++)
{

View File

@ -31,11 +31,9 @@ public class Commandinvsee extends EssentialsCommand
{
invUser.getInventory().setContents(user.getSavedInventory());
user.setSavedInventory(null);
user.sendMessage(Util.i18n("invRestored"));
return;
throw new Exception(Util.i18n("invRestored"));
}
charge(user);
if (user.getSavedInventory() == null)
{
user.setSavedInventory(user.getInventory().getContents());

View File

@ -31,8 +31,7 @@ public class Commanditem extends EssentialsCommand
: (!user.isAuthorized("essentials.itemspawn.exempt")
&& !user.canSpawnItem(stack.getTypeId())))
{
user.sendMessage(Util.format("cantSpawnItem", itemname));
return;
throw new Exception(Util.format("cantSpawnItem", itemname));
}
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
@ -42,12 +41,10 @@ public class Commanditem extends EssentialsCommand
if (stack.getType() == Material.AIR)
{
user.sendMessage(Util.format("cantSpawnItem", "Air"));
return;
throw new Exception(Util.format("cantSpawnItem", "Air"));
}
String itemName = stack.getType().toString().toLowerCase().replace('_', ' ');
charge(user);
user.sendMessage(Util.format("itemSpawn", stack.getAmount(), itemName));
user.getInventory().addItem(stack);
user.updateInventory();

View File

@ -26,10 +26,8 @@ public class Commandkick extends EssentialsCommand
User player = getPlayer(server, args, 0);
if (player.isAuthorized("essentials.kick.exempt"))
{
sender.sendMessage(Util.i18n("kickExempt"));
return;
throw new Exception(Util.i18n("kickExempt"));
}
charge(sender);
final String kickReason = args.length > 1 ? getFinalArg(args, 1) : Util.i18n("kickDefault");
player.kickPlayer(kickReason);
String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;

View File

@ -16,8 +16,6 @@ public class Commandkickall extends EssentialsCommand
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
charge(sender);
for (Player p : server.getOnlinePlayers())
{
if (sender instanceof Player && p.getName().equalsIgnoreCase(((Player)sender).getName()))

View File

@ -21,7 +21,6 @@ public class Commandkill extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(sender);
for (Player p : server.matchPlayer(args[0]))
{
p.setHealth(0);

View File

@ -141,7 +141,6 @@ public class Commandkit extends EssentialsCommand
}
try
{
charge(user);
charge.charge(user);
}
catch (Exception ex)

View File

@ -26,20 +26,14 @@ public class Commandlightning extends EssentialsCommand
if (args.length < 1 & user != null)
{
user.getWorld().strikeLightning(user.getTargetBlock(null, 600).getLocation());
charge(user);
return;
}
if (server.matchPlayer(args[0]).isEmpty())
{
sender.sendMessage(Util.i18n("playerNotFound"));
return;
throw new Exception(Util.i18n("playerNotFound"));
}
if (user != null)
{
charge(user);
}
for (Player p : server.matchPlayer(args[0]))
{
sender.sendMessage(Util.format("lightningUse", p.getDisplayName()));

View File

@ -44,7 +44,6 @@ public class Commandlist extends EssentialsCommand
playerHidden++;
}
}
charge(sender);
//TODO: move these to messages file
StringBuilder online = new StringBuilder();
online.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length - playerHidden);

View File

@ -23,22 +23,19 @@ public class Commandmail extends EssentialsCommand
List<String> mail = user.getMails();
if (mail.isEmpty())
{
user.sendMessage(Util.i18n("noMail"));
return;
throw new Exception(Util.i18n("noMail"));
}
for (String s : mail)
{
user.sendMessage(s);
}
user.sendMessage(Util.i18n("mailClear"));
return;
throw new Exception(Util.i18n("mailClear"));
}
if (args.length >= 3 && "send".equalsIgnoreCase(args[0]))
{
if (!user.isAuthorized("essentials.mail.send"))
{
user.sendMessage(Util.i18n("noMailSendPerm"));
return;
throw new Exception(Util.i18n("noMailSendPerm"));
}
Player player = server.getPlayer(args[1]);
@ -53,10 +50,8 @@ public class Commandmail extends EssentialsCommand
}
if (u == null)
{
user.sendMessage(Util.format("playerNeverOnServer", args[1]));
return;
throw new Exception(Util.format("playerNeverOnServer", args[1]));
}
charge(user);
if (!u.isIgnoredPlayer(user.getName()))
{
u.addMail(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2));
@ -67,8 +62,7 @@ public class Commandmail extends EssentialsCommand
if (args.length >= 1 && "clear".equalsIgnoreCase(args[0]))
{
user.setMails(null);
user.sendMessage(Util.i18n("mailCleared"));
return;
throw new Exception(Util.i18n("mailCleared"));
}
throw new NotEnoughArgumentsException();
}

View File

@ -17,8 +17,7 @@ public class Commandme extends EssentialsCommand
{
if (user.isMuted())
{
user.sendMessage(Util.i18n("voiceSilenced"));
return;
throw new Exception(Util.i18n("voiceSilenced"));
}
if (args.length < 1)
@ -31,7 +30,6 @@ public class Commandme extends EssentialsCommand
message.append(args[i]);
message.append(' ');
}
charge(user);
ess.broadcastMessage(user.getName(), "* " + user.getDisplayName() + " " + message);
}
}

View File

@ -15,7 +15,6 @@ public class Commandmotd extends EssentialsCommand
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
charge(sender);
for (String m : ess.getMotd(sender, Util.i18n("noMotd")))
{
sender.sendMessage(m);

View File

@ -30,8 +30,7 @@ public class Commandmsg extends EssentialsCommand
User user = ess.getUser(sender);
if (user.isMuted())
{
user.sendMessage(Util.i18n("voiceSilenced"));
return;
throw new Exception(Util.i18n("voiceSilenced"));
}
}
@ -55,8 +54,7 @@ public class Commandmsg extends EssentialsCommand
if (matches.isEmpty())
{
sender.sendMessage(Util.i18n("playerNotFound"));
return;
throw new Exception(Util.i18n("playerNotFound"));
}
int i = 0;
@ -70,11 +68,9 @@ public class Commandmsg extends EssentialsCommand
}
if (i == matches.size())
{
sender.sendMessage(Util.i18n("playerNotFound"));
return;
throw new Exception(Util.i18n("playerNotFound"));
}
charge(sender);
for (Player p : matches)
{
sender.sendMessage(Util.format("msgFormat", translatedMe, p.getDisplayName(), message));

View File

@ -24,8 +24,7 @@ public class Commandmute extends EssentialsCommand
User p = getPlayer(server, args, 0, true);
if (!p.isMuted() && p.isAuthorized("essentials.mute.exempt"))
{
sender.sendMessage(Util.i18n("muteExempt"));
return;
throw new Exception(Util.i18n("muteExempt"));
}
long muteTimestamp = 0;
if (args.length > 1)
@ -34,7 +33,6 @@ public class Commandmute extends EssentialsCommand
muteTimestamp = Util.parseDateDiff(time, true);
}
p.setMuteTimeout(muteTimestamp);
charge(sender);
boolean muted = p.toggleMuted();
sender.sendMessage(
muted

View File

@ -23,16 +23,14 @@ public class Commandnick extends EssentialsCommand
}
if (!ess.getSettings().changeDisplayName()) {
user.sendMessage(Util.i18n("nickDisplayName"));
return;
throw new Exception(Util.i18n("nickDisplayName"));
}
if (args.length > 1)
{
if (!user.isAuthorized("essentials.nick.others"))
{
user.sendMessage(Util.i18n("nickOthersPermission"));
return;
throw new Exception(Util.i18n("nickOthersPermission"));
}
setOthersNickname(server, user, args);
@ -51,8 +49,7 @@ public class Commandnick extends EssentialsCommand
if (nick.matches("[^a-zA-Z_0-9]"))
{
user.sendMessage(Util.i18n("nickNamesAlpha"));
return;
throw new Exception(Util.i18n("nickNamesAlpha"));
}
for (Player p : server.getOnlinePlayers())
@ -66,12 +63,10 @@ public class Commandnick extends EssentialsCommand
String nk = nick.toLowerCase();
if (nk.equals(dn) || nk.equals(n))
{
user.sendMessage(Util.i18n("nickInUse"));
return;
throw new Exception(Util.i18n("nickInUse"));
}
}
charge(user);
user.setDisplayName(ess.getSettings().getNicknamePrefix() + nick);
user.setNickname(nick);
user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7."));

View File

@ -1,173 +0,0 @@
package com.earth2me.essentials.commands;
import java.io.File;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class Commandplugin extends EssentialsCommand
{
private Server server;
public Commandplugin()
{
super("plugin");
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
this.server = server;
PluginCommands sub = null;
try
{
sub = PluginCommands.valueOf(args[0].toUpperCase());
}
catch (Exception ex)
{
sender.sendMessage("§cUsage: /plugin [load|reload|enable|disable|list] [PluginName]");
return;
}
switch (sub)
{
case LOAD: // All disable functions are broken until
// http://leaky.bukkit.org/issues/641 is fixed.
sender.sendMessage("This function is broken. Performing /reload now.");
server.reload();
/*if (args.length < 2) return;
User.charge(sender, this);
loadPlugin(args[1], sender);*/
return;
case RELOAD:
sender.sendMessage("This function is broken. Performing /reload now.");
server.reload();
/*if (args.length < 2) return;
User.charge(sender, this);
reloadPlugin(args[1], sender);*/
return;
case ENABLE:
sender.sendMessage("This function is broken. Performing /reload now.");
server.reload();
/*if (args.length < 2) return;
User.charge(sender, this);
enablePlugin(args[1], sender);*/
return;
case DISABLE:
sender.sendMessage("This function is broken.");
/*if (args.length < 2) return;
User.charge(sender, this);
disablePlugin(args[1], sender);*/
return;
case LIST:
charge(sender);
listPlugins(sender);
return;
}
}
private void listPlugins(CommandSender player)
{
StringBuilder plugins = new StringBuilder();
for (Plugin p : server.getPluginManager().getPlugins())
{
plugins.append(p.isEnabled() ? " §a" : " §c");
plugins.append(p.getDescription().getName());
}
plugins.insert(0, "§7Plugins:§f");
player.sendMessage(plugins.toString());
}
private boolean reloadPlugin(String name, CommandSender player)
{
return disablePlugin(name, player) && enablePlugin(name, player);
}
private boolean loadPlugin(String name, CommandSender sender)
{
try
{
PluginManager pm = server.getPluginManager();
pm.loadPlugin(new File("plugins", name + ".jar"));
sender.sendMessage("§7Plugin loaded.");
return enablePlugin(name, sender);
}
catch (Throwable ex)
{
sender.sendMessage("§cCould not load plugin. Is the file named properly?");
return false;
}
}
private boolean enablePlugin(String name, CommandSender sender)
{
try
{
final PluginManager pm = server.getPluginManager();
final Plugin plugin = pm.getPlugin(name);
if (!plugin.isEnabled())
{
new Thread(new Runnable()
{
public void run()
{
synchronized (pm)
{
pm.enablePlugin(plugin);
}
}
}).start();
}
sender.sendMessage("§7Plugin enabled.");
return true;
}
catch (Throwable ex)
{
listPlugins(sender);
return false;
}
}
private boolean disablePlugin(String name, CommandSender sender)
{
try
{
final PluginManager pm = server.getPluginManager();
final Plugin plugin = pm.getPlugin(name);
if (plugin.isEnabled())
{
new Thread(new Runnable()
{
public void run()
{
synchronized (pm)
{
pm.disablePlugin(plugin);
}
}
}).start();
}
sender.sendMessage("§7Plugin disabled.");
return true;
}
catch (Throwable ex)
{
listPlugins(sender);
return false;
}
}
private enum PluginCommands
{
LOAD, RELOAD, LIST, ENABLE, DISABLE
}
}

View File

@ -23,8 +23,7 @@ public class Commandpowertool extends EssentialsCommand
List<String> powertools = user.getPowertool(is);
if (is == null || is.getType() == Material.AIR)
{
user.sendMessage(Util.i18n("powerToolAir"));
return;
throw new Exception(Util.i18n("powerToolAir"));
}
String itemName = is.getType().toString().toLowerCase().replaceAll("_", " ");
@ -35,7 +34,7 @@ public class Commandpowertool extends EssentialsCommand
{
if (powertools == null || powertools.isEmpty())
{
user.sendMessage(Util.format("powerToolListEmpty", itemName));
throw new Exception(Util.format("powerToolListEmpty", itemName));
}
else
{
@ -50,8 +49,7 @@ public class Commandpowertool extends EssentialsCommand
command = command.substring(2);
if (!powertools.contains(command))
{
user.sendMessage(Util.format("powerToolNoSuchCommandAssigned", command, itemName));
return;
throw new Exception(Util.format("powerToolNoSuchCommandAssigned", command, itemName));
}
powertools.remove(command);
@ -70,8 +68,7 @@ public class Commandpowertool extends EssentialsCommand
command = command.substring(2);
if(powertools.contains(command))
{
user.sendMessage(Util.format("powerToolAlreadySet", command, itemName));
return;
throw new Exception(Util.format("powerToolAlreadySet", command, itemName));
}
}
else if (powertools != null && !powertools.isEmpty())
@ -94,7 +91,6 @@ public class Commandpowertool extends EssentialsCommand
user.sendMessage(Util.format("powerToolRemoveAll", itemName));
}
charge(user);
user.setPowertool(is, powertools);
}
}

View File

@ -32,11 +32,9 @@ public class Commandr extends EssentialsCommand
if (target == null)
{
sender.sendMessage(Util.i18n("foreverAlone"));
return;
throw new Exception(Util.i18n("foreverAlone"));
}
charge(sender);
sender.sendMessage(Util.format("msgFormat", Util.i18n("me"), targetName, message));
if (target instanceof Player)
{

View File

@ -22,7 +22,6 @@ public class Commandrealname extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
final String whois = args[0].toLowerCase();
charge(user);
for (Player p : server.getOnlinePlayers())
{
final User u = ess.getUser(p);

View File

@ -15,7 +15,6 @@ public class Commandreloadall extends EssentialsCommand
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
charge(sender);
server.reload();
sender.sendMessage(Util.i18n("reloadAllPlugins"));
}

View File

@ -33,28 +33,12 @@ public class Commandrepair extends EssentialsCommand
final String itemName = item.getType().toString().toLowerCase();
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);
try
{
charge.isAffordableFor(user);
}
catch (Exception ex)
{
user.sendMessage(ex.getMessage());
return;
}
charge.isAffordableFor(user);
repairItem(item);
try
{
repairItem(item);
}
catch (Exception e)
{
user.sendMessage(e.getMessage());
return;
}
charge.charge(user);
charge(user);
user.sendMessage(Util.format("repair", itemName.replace('_', ' ')));
}
else if (args[0].equalsIgnoreCase("all"))
@ -66,11 +50,10 @@ public class Commandrepair extends EssentialsCommand
if (repaired.isEmpty())
{
user.sendMessage(Util.format("repairNone"));
throw new Exception(Util.format("repairNone"));
}
else
{
charge(user);
user.sendMessage(Util.format("repair", Util.joinList(repaired)));
}

View File

@ -15,7 +15,6 @@ public class Commandrules extends EssentialsCommand
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
charge(sender);
for (String m : ess.getLines(sender, "rules", Util.i18n("noRules")))
{
sender.sendMessage(m);

View File

@ -145,11 +145,9 @@ public class Commandsell extends EssentialsCommand
{
user.sendMessage(Util.i18n("itemNotEnough1"));
user.sendMessage(Util.i18n("itemNotEnough2"));
user.sendMessage(Util.i18n("itemNotEnough3"));
return;
throw new Exception(Util.i18n("itemNotEnough3"));
}
charge(user);
final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability());
InventoryWorkaround.removeItem(user.getInventory(), true, ris);
user.updateInventory();

View File

@ -66,7 +66,6 @@ public class Commandsethome extends EssentialsCommand
{
user.setHome();
}
charge(user);
user.sendMessage(Util.i18n("homeSet"));
}

View File

@ -15,12 +15,10 @@ public class Commandsetjail extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
charge(user);
ess.getJail().setJail(user.getLocation(), args[0]);
user.sendMessage(Util.format("jailSet",args[0]));

View File

@ -21,7 +21,6 @@ public class Commandsetwarp extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(user);
Location loc = user.getLocation();
ess.getWarps().setWarp(args[0], loc);
user.sendMessage(Util.format("warpSet", args[0]));

View File

@ -22,7 +22,6 @@ public class Commandsetworth extends EssentialsCommand
}
ItemStack stack = ess.getItemDb().get(args[0]);
charge(user);
ess.getWorth().setPrice(stack, Double.parseDouble(args[1]));
user.sendMessage(Util.i18n("worthSet"));
}

View File

@ -15,9 +15,6 @@ public class Commandsocialspy extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
user.sendMessage("§7SocialSpy " + (user.toggleSocialSpy() ? Util.i18n("enabled") : Util.i18n("disabled")));
}
}

View File

@ -31,7 +31,6 @@ public class Commandspawner extends EssentialsCommand
throw new Exception(Util.i18n("mobSpawnTarget"));
}
charge(user);
try
{
String name = args[0];

View File

@ -59,8 +59,7 @@ public class Commandspawnmob extends EssentialsCommand
if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase())
|| (mountType != null && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase())))
{
user.sendMessage(Util.i18n("unableToSpawnMob"));
return;
throw new Exception(Util.i18n("unableToSpawnMob"));
}
Entity spawnedMob = null;
@ -71,10 +70,8 @@ public class Commandspawnmob extends EssentialsCommand
mob = Mob.fromName(mobType);
if (mob == null)
{
user.sendMessage(Util.i18n("invalidMob"));
return;
throw new Exception(Util.i18n("invalidMob"));
}
charge(user);
int[] ignore =
{
8, 9

View File

@ -15,7 +15,6 @@ public class Commandsuicide extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
user.setHealth(0);
user.sendMessage(Util.i18n("suicideMessage"));
ess.broadcastMessage(user.getName(),

View File

@ -16,13 +16,11 @@ public class Commandthunder extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
charge(user);
World world = user.getWorld();
boolean setThunder = args[0].equalsIgnoreCase("true");
if (args.length > 1)

View File

@ -45,7 +45,6 @@ public class Commandtogglejail extends EssentialsCommand
return;
}
}
charge(sender);
if (!(p.getBase() instanceof OfflinePlayer))
{
ess.getJail().sendToJail(p, args[1]);

View File

@ -20,7 +20,6 @@ public class Commandtop extends EssentialsCommand
int topX = user.getLocation().getBlockX();
int topZ = user.getLocation().getBlockZ();
int topY = user.getWorld().getHighestBlockYAt(topX, topZ);
charge(user);
user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess));
user.sendMessage(Util.i18n("teleportTop"));
}

View File

@ -41,7 +41,6 @@ public class Commandtp extends EssentialsCommand
throw new Exception("You need access to /tpohere to teleport other players.");
}
user.sendMessage(Util.i18n("teleporting"));
charge(user);
User target = getPlayer(server, args, 0);
User toPlayer = getPlayer(server, args, 1);
target.getTeleport().now(toPlayer, false);

View File

@ -25,7 +25,6 @@ public class Commandtpa extends EssentialsCommand
{
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
charge(user);
if (!p.isIgnoredPlayer(user.getName()))
{
p.requestTeleport(user, false);

View File

@ -21,7 +21,6 @@ public class Commandtpaall extends EssentialsCommand
{
if (sender instanceof Player)
{
charge(sender);
teleportAAllPlayers(server, sender, ess.getUser(sender));
return;
}
@ -29,7 +28,6 @@ public class Commandtpaall extends EssentialsCommand
}
User p = getPlayer(server, args, 0);
charge(sender);
teleportAAllPlayers(server, sender, p);
}

View File

@ -25,7 +25,6 @@ public class Commandtpahere extends EssentialsCommand
{
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
charge(user);
p.requestTeleport(user, true);
p.sendMessage(Util.format("teleportHereRequest", user.getDisplayName()));
p.sendMessage(Util.i18n("typeTpaccept"));

View File

@ -21,7 +21,6 @@ public class Commandtpall extends EssentialsCommand
{
if (sender instanceof Player)
{
charge(sender);
teleportAllPlayers(server, sender, ess.getUser(sender));
return;
}
@ -29,7 +28,6 @@ public class Commandtpall extends EssentialsCommand
}
User p = getPlayer(server, args, 0);
charge(sender);
teleportAllPlayers(server, sender, p);
}

View File

@ -21,7 +21,6 @@ public class Commandtpdeny extends EssentialsCommand
throw new Exception(Util.i18n("noPendingRequest"));
}
charge(user);
user.sendMessage(Util.i18n("requestDenied"));
p.sendMessage(Util.format("requestDeniedFrom", user.getDisplayName()));
user.requestTeleport(null, false);

View File

@ -32,7 +32,6 @@ public class Commandtpo extends EssentialsCommand
// Verify permission
if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden"))
{
charge(user);
user.getTeleport().now(p, false);
user.sendMessage(Util.i18n("teleporting"));
}

View File

@ -33,7 +33,6 @@ public class Commandtpohere extends EssentialsCommand
// Verify permission
if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden"))
{
charge(user);
p.getTeleport().now(user, false);
user.sendMessage(Util.i18n("teleporting"));
}

View File

@ -15,7 +15,6 @@ public class Commandtptoggle extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
user.sendMessage(user.toggleTeleportEnabled()
? Util.i18n("teleportationEnabled")
: Util.i18n("teleportationDisabled"));

View File

@ -51,7 +51,6 @@ public class Commandtree extends EssentialsCommand
final boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree);
if (success)
{
charge(user);
user.sendMessage(Util.i18n("treeSpawned"));
}
else

View File

@ -93,8 +93,7 @@ public class Commandunlimited extends EssentialsCommand
&& !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET)
&& user.isAuthorized("essentials.unlimited.item-bucket"))))
{
user.sendMessage(Util.format("unlimitedItemPermission", itemname));
return false;
throw new Exception(Util.format("unlimitedItemPermission", itemname));
}
String message = "disableUnlimited";
@ -103,7 +102,6 @@ public class Commandunlimited extends EssentialsCommand
{
message = "enableUnlimited";
enableUnlimited = true;
charge(user);
if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack))
{
target.getInventory().addItem(stack);

View File

@ -23,7 +23,6 @@ public class Commandweather extends EssentialsCommand
boolean isStorm = args[0].equalsIgnoreCase("storm");
World world = user.getWorld();
charge(user);
if (args.length > 1)
{

View File

@ -35,7 +35,6 @@ public class Commandwhois extends EssentialsCommand
showhidden = true;
}
String whois = args[0].toLowerCase();
charge(sender);
int prefixLength = ChatColor.stripColor(ess.getSettings().getNicknamePrefix()).length();
for (Player p : server.getOnlinePlayers())
{

View File

@ -43,7 +43,6 @@ public class Commandworth extends EssentialsCommand
throw new Exception(Util.i18n("itemCannotBeSold"));
}
charge(user);
user.sendMessage(is.getDurability() != 0
? Util.format("worthMeta",
is.getType().toString().toLowerCase().replace("_", ""),

View File

@ -79,7 +79,10 @@ public abstract class EssentialsCommand implements IEssentialsCommand
@Override
public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception
{
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
run(server, user, commandLabel, args);
charge.charge(user);
}
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
@ -111,13 +114,4 @@ public abstract class EssentialsCommand implements IEssentialsCommand
}
return bldr.toString();
}
protected void charge(final CommandSender sender) throws ChargeException
{
if (sender instanceof Player)
{
final Trade charge = new Trade(this.getName(), ess);
charge.charge(ess.getUser((Player)sender));
}
}
}