From 6427a93d1496fa3208415e8cda06ff765eba6cfa Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 27 Aug 2011 23:14:49 +0200 Subject: 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. --- .../earth2me/essentials/commands/Commandafk.java | 2 - .../essentials/commands/Commandantioch.java | 1 - .../essentials/commands/Commandbackup.java | 3 +- .../essentials/commands/Commandbalance.java | 1 - .../essentials/commands/Commandbigtree.java | 3 +- .../essentials/commands/Commandbroadcast.java | 1 - .../earth2me/essentials/commands/Commandburn.java | 1 - .../essentials/commands/Commandclearinventory.java | 3 - .../essentials/commands/Commandessentials.java | 1 - .../earth2me/essentials/commands/Commandext.java | 2 - .../essentials/commands/Commandfireball.java | 1 - .../earth2me/essentials/commands/Commandgc.java | 1 - .../essentials/commands/Commandgetpos.java | 1 - .../earth2me/essentials/commands/Commandgive.java | 7 +- .../earth2me/essentials/commands/Commandgod.java | 1 - .../earth2me/essentials/commands/Commandheal.java | 2 - .../essentials/commands/Commandhelpop.java | 1 - .../earth2me/essentials/commands/Commandinfo.java | 6 +- .../essentials/commands/Commandinvsee.java | 4 +- .../earth2me/essentials/commands/Commanditem.java | 7 +- .../earth2me/essentials/commands/Commandkick.java | 4 +- .../essentials/commands/Commandkickall.java | 2 - .../earth2me/essentials/commands/Commandkill.java | 1 - .../earth2me/essentials/commands/Commandkit.java | 1 - .../essentials/commands/Commandlightning.java | 8 +- .../earth2me/essentials/commands/Commandlist.java | 1 - .../earth2me/essentials/commands/Commandmail.java | 16 +- .../earth2me/essentials/commands/Commandme.java | 4 +- .../earth2me/essentials/commands/Commandmotd.java | 1 - .../earth2me/essentials/commands/Commandmsg.java | 10 +- .../earth2me/essentials/commands/Commandmute.java | 4 +- .../earth2me/essentials/commands/Commandnick.java | 13 +- .../essentials/commands/Commandplugin.java | 173 --------------------- .../essentials/commands/Commandpowertool.java | 12 +- .../com/earth2me/essentials/commands/Commandr.java | 4 +- .../essentials/commands/Commandrealname.java | 1 - .../essentials/commands/Commandreloadall.java | 1 - .../essentials/commands/Commandrepair.java | 25 +-- .../earth2me/essentials/commands/Commandrules.java | 1 - .../earth2me/essentials/commands/Commandsell.java | 4 +- .../essentials/commands/Commandsethome.java | 1 - .../essentials/commands/Commandsetjail.java | 2 - .../essentials/commands/Commandsetwarp.java | 1 - .../essentials/commands/Commandsetworth.java | 1 - .../essentials/commands/Commandsocialspy.java | 3 - .../essentials/commands/Commandspawner.java | 1 - .../essentials/commands/Commandspawnmob.java | 7 +- .../essentials/commands/Commandsuicide.java | 1 - .../essentials/commands/Commandthunder.java | 2 - .../essentials/commands/Commandtogglejail.java | 1 - .../earth2me/essentials/commands/Commandtop.java | 1 - .../earth2me/essentials/commands/Commandtp.java | 1 - .../earth2me/essentials/commands/Commandtpa.java | 1 - .../essentials/commands/Commandtpaall.java | 2 - .../essentials/commands/Commandtpahere.java | 1 - .../earth2me/essentials/commands/Commandtpall.java | 2 - .../essentials/commands/Commandtpdeny.java | 1 - .../earth2me/essentials/commands/Commandtpo.java | 1 - .../essentials/commands/Commandtpohere.java | 1 - .../essentials/commands/Commandtptoggle.java | 1 - .../earth2me/essentials/commands/Commandtree.java | 1 - .../essentials/commands/Commandunlimited.java | 4 +- .../essentials/commands/Commandweather.java | 1 - .../earth2me/essentials/commands/Commandwhois.java | 1 - .../earth2me/essentials/commands/Commandworth.java | 1 - .../essentials/commands/EssentialsCommand.java | 12 +- 66 files changed, 40 insertions(+), 347 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandplugin.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index 64ae40c22..9fe17d5a0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -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])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java index 4dd3042d0..c30975b03 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java @@ -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."); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 8f6e8e8bf..6bbf8361c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 7dd1fb449..d26df68cb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -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")) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 8370896b1..ded3ffdaf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -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")); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index 3ca9d3fd0..684920114 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -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))); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java index e63331203..5df3cb5d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 09496c7a2..447689691 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index bf0226138..fda7061d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -102,7 +102,6 @@ public class Commandessentials extends EssentialsCommand return; } ess.reload(); - charge(sender); sender.sendMessage(Util.format("essentialsReload", ess.getDescription().getVersion())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index 339351ef1..afb9fa3a6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -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())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java index 73c314935..19e7eddf1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java @@ -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); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index dd3cf35f4..28164bd78 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -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))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index 517ef0c9a..bf5cff75d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -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)"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 68bfe8a30..065b76d03 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -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(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 6bb9f1390..d4c35e113 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -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]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index effe64604..d60fc09fe 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 261cad062..158b0d40b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -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()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java index 4db469b58..97dd71d35 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java @@ -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++) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java index e5877fe40..8b6dc8182 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java @@ -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()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 79e8344f1..352ce18eb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -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(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index e9b3720fe..fd0d4a8e0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -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; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index c52dc8d14..8d36f50d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -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())) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java index c849463b7..03afeadc4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java @@ -21,7 +21,6 @@ public class Commandkill extends EssentialsCommand throw new NotEnoughArgumentsException(); } - charge(sender); for (Player p : server.matchPlayer(args[0])) { p.setHealth(0); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 7f9a91590..75cc83887 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -141,7 +141,6 @@ public class Commandkit extends EssentialsCommand } try { - charge(user); charge.charge(user); } catch (Exception ex) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index c9135d61e..dc4387833 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -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())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index ef7d6e9f8..98066d7e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index b54b88a12..a98fabbd2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -23,22 +23,19 @@ public class Commandmail extends EssentialsCommand List 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(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 098558f11..7441b723b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -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); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java index 4712c331b..c695338f6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 42f17bed2..f14935648 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -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)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index e56ddc42c..1777c5b48 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -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 diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 99c779ba4..253ec7646 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -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.")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java b/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java deleted file mode 100644 index 9e7939d57..000000000 --- a/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java +++ /dev/null @@ -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 - } -} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 4c3d941ae..742535a77 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -23,8 +23,7 @@ public class Commandpowertool extends EssentialsCommand List 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); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index d89947500..daf83034a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -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) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index e16d59198..5e12c535d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java b/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java index eeee08e11..bd4f59dcc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index d41f5580f..029901867 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -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))); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java index 1b00bea47..39f7de68e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index f471364d5..658782b9a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -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(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 7f496371f..d9bd32c30 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -66,7 +66,6 @@ public class Commandsethome extends EssentialsCommand { user.setHome(); } - charge(user); user.sendMessage(Util.i18n("homeSet")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index 76fe766c3..d9b0eac4d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -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])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java index 4e799d6c0..ccdacab57 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -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])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index e6b741c43..086b1549d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 33efffeef..8e95e8237 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -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"))); - } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 926c219c1..d3b14970a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -31,7 +31,6 @@ public class Commandspawner extends EssentialsCommand throw new Exception(Util.i18n("mobSpawnTarget")); } - charge(user); try { String name = args[0]; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 4cef00de6..87a22c59f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -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 diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index 57e5e3fd5..90f40a4bf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -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(), diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index b1ffd3f7f..34f5c3fed 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -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) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 75abda4bb..6f60f7f43 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -45,7 +45,6 @@ public class Commandtogglejail extends EssentialsCommand return; } } - charge(sender); if (!(p.getBase() instanceof OfflinePlayer)) { ess.getJail().sendToJail(p, args[1]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 8c0c687d0..ee5bfbe45 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index c147c5d25..c3cc8f7e5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index f3b7ae505..32cbe3bd9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index 25c5d2892..97897852f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -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); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 2003bbf73..935721345 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -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")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index cc58944d7..1cb6321ea 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -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); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java index e31d7ae3c..5d7764ae6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index 18d818ea1..5a4e082e0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index 186476a50..7af39854f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -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")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 38236d475..f880c5d34 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -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")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index 81be2a329..8013453ab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -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 diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index 122891e02..cebbcaf8c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index eec1d9575..45c62d787 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -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) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index ef815dd87..1769202f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -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()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index f2d6ed954..b59070320 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -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("_", ""), diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index c99cdfdc9..58da18c21 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -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)); - } - } } -- cgit v1.2.3