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 | 6af79ef41935b89c643beedb50732d7879b5b0da (patch) | |
tree | 525b74155eaecbdf066a16070ebd2645e40631e9 | |
parent | be4891601f3f799103a08dc42287e6e0083441d3 (diff) | |
download | Essentials-6af79ef41935b89c643beedb50732d7879b5b0da.tar Essentials-6af79ef41935b89c643beedb50732d7879b5b0da.tar.gz Essentials-6af79ef41935b89c643beedb50732d7879b5b0da.tar.lz Essentials-6af79ef41935b89c643beedb50732d7879b5b0da.tar.xz Essentials-6af79ef41935b89c643beedb50732d7879b5b0da.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); |