diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-04-03 15:35:13 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-04-03 15:35:13 +0100 |
commit | d0f3fb4417a89f42d16c4447fec26b70f667745a (patch) | |
tree | d4fd73b0c92e76a20ee055e9d39d59ec37d415e7 | |
parent | 37370f722c5920a279c95347987b06f13be8527e (diff) | |
download | Essentials-d0f3fb4417a89f42d16c4447fec26b70f667745a.tar Essentials-d0f3fb4417a89f42d16c4447fec26b70f667745a.tar.gz Essentials-d0f3fb4417a89f42d16c4447fec26b70f667745a.tar.lz Essentials-d0f3fb4417a89f42d16c4447fec26b70f667745a.tar.xz Essentials-d0f3fb4417a89f42d16c4447fec26b70f667745a.zip |
Command cost api update: Can now set fallback costs.
Repair command addition: ontop of 'repair' and 'repair-<itemname>' you can now charge for 'repair-all' to charge more for /repair all or 'repair-item' to charge per item repaired.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Trade.java | 21 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/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<String> repaired = new ArrayList<String>(); 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); |