From d0f3fb4417a89f42d16c4447fec26b70f667745a Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 3 Apr 2012 15:35:13 +0100 Subject: [PATCH] Command cost api update: Can now set fallback costs. Repair command addition: ontop of 'repair' and 'repair-' you can now charge for 'repair-all' to charge more for /repair all or 'repair-item' to charge per item repaired. --- .../src/com/earth2me/essentials/Trade.java | 21 ++++++++++++++----- .../essentials/commands/Commandrepair.java | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java index 730037d9a..3d3f36d8c 100644 --- a/Essentials/src/com/earth2me/essentials/Trade.java +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -20,6 +20,7 @@ import org.bukkit.inventory.ItemStack; public class Trade { private final transient String command; + private final transient String fallbackCommand; private final transient Double money; private final transient ItemStack itemStack; private final transient Integer exp; @@ -27,27 +28,33 @@ public class Trade public Trade(final String command, final IEssentials ess) { - this(command, null, null, null, ess); + this(command, null, null, null, null, ess); + } + + public Trade(final String command, final String fallback, final IEssentials ess) + { + this(command, fallback, null, null, null, ess); } public Trade(final double money, final IEssentials ess) { - this(null, money, null, null, ess); + this(null, null, money, null, null, ess); } public Trade(final ItemStack items, final IEssentials ess) { - this(null, null, items, null, ess); + this(null, null, null, items, null, ess); } public Trade(final int exp, final IEssentials ess) { - this(null, null, null, exp, ess); + this(null, null, null, null, exp, ess); } - private Trade(final String command, final Double money, final ItemStack item, final Integer exp, final IEssentials ess) + private Trade(final String command, final String fallback, final Double money, final ItemStack item, final Integer exp, final IEssentials ess) { this.command = command; + this.fallbackCommand = fallback; this.money = money; this.itemStack = item; this.exp = exp; @@ -197,6 +204,10 @@ public class Trade && !user.isAuthorized("essentials.nocommandcost." + command)) { cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); + if (cost == 0.0 && fallbackCommand != null && !fallbackCommand.isEmpty()) + { + cost = ess.getSettings().getCommandCost(fallbackCommand.charAt(0) == '/' ? fallbackCommand.substring(1) : fallbackCommand); + } } return cost; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index 8d1278fd0..d621109f7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -53,6 +53,8 @@ public class Commandrepair extends EssentialsCommand } else if (args[0].equalsIgnoreCase("all")) { + final Trade charge = new Trade("repair-all", ess); + charge.isAffordableFor(user); final List repaired = new ArrayList(); repairItems(user.getInventory().getContents(), user, repaired); @@ -69,6 +71,7 @@ public class Commandrepair extends EssentialsCommand { user.sendMessage(_("repair", Util.joinList(repaired))); } + charge.charge(user); } else @@ -102,7 +105,7 @@ public class Commandrepair extends EssentialsCommand continue; } final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH); - final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess); + final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), "repair-item", ess); try { charge.isAffordableFor(user);