summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/Charge.java
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/Charge.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/Charge.java81
1 files changed, 36 insertions, 45 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Charge.java b/Essentials/src/com/earth2me/essentials/Charge.java
index 5098b3b1f..a84bfa918 100644
--- a/Essentials/src/com/earth2me/essentials/Charge.java
+++ b/Essentials/src/com/earth2me/essentials/Charge.java
@@ -5,27 +5,27 @@ import org.bukkit.inventory.ItemStack;
public class Charge
{
- private final String command;
- private final Double costs;
- private final ItemStack items;
- private final IEssentials ess;
+ private final transient String command;
+ private final transient Double costs;
+ private final transient ItemStack items;
+ private final transient IEssentials ess;
- public Charge(String command, IEssentials ess)
+ public Charge(final String command, final IEssentials ess)
{
this(command, null, null, ess);
}
- public Charge(double money, IEssentials ess)
+ public Charge(final double money, final IEssentials ess)
{
this(null, money, null, ess);
}
- public Charge(ItemStack items, IEssentials ess)
+ public Charge(final ItemStack items, final IEssentials ess)
{
this(null, null, items, ess);
}
-
- private Charge(String command, Double money, ItemStack item, IEssentials ess)
+
+ private Charge(final String command, final Double money, final ItemStack item, final IEssentials ess)
{
this.command = command;
this.costs = money;
@@ -33,46 +33,40 @@ public class Charge
this.ess = ess;
}
- public void isAffordableFor(IUser user) throws Exception
+ public void isAffordableFor(final IUser user) throws ChargeException
{
- double mon = user.getMoney();
- if (costs != null)
+ final double mon = user.getMoney();
+ if (costs != null
+ && mon < costs
+ && !user.isAuthorized("essentials.eco.loan"))
{
- if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
- if (items != null)
+
+ if (items != null
+ && !InventoryWorkaround.containsItem(user.getInventory(), true, items))
{
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
- {
- throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
- }
+ throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
}
- if (command != null && !command.isEmpty())
+
+ if (command != null && !command.isEmpty()
+ && !user.isAuthorized("essentials.nocommandcost.all")
+ && !user.isAuthorized("essentials.nocommandcost." + command)
+ && mon < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
+ && !user.isAuthorized("essentials.eco.loan"))
{
- if (user.isAuthorized("essentials.nocommandcost.all")
- || user.isAuthorized("essentials.nocommandcost." + command))
- {
- return;
- }
- double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
- if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
}
- public void charge(IUser user) throws Exception
+ public void charge(final IUser user) throws ChargeException
{
- double mon = user.getMoney();
if (costs != null)
{
+ final double mon = user.getMoney();
if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
{
- throw new Exception(Util.i18n("notEnoughMoney"));
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
user.takeMoney(costs);
}
@@ -80,23 +74,20 @@ public class Charge
{
if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
{
- throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
+ throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
}
InventoryWorkaround.removeItem(user.getInventory(), true, items);
user.updateInventory();
}
- if (command != null && !command.isEmpty())
+ if (command != null && !command.isEmpty()
+ && !user.isAuthorized("essentials.nocommandcost.all")
+ && !user.isAuthorized("essentials.nocommandcost." + command))
{
- if (user.isAuthorized("essentials.nocommandcost.all")
- || user.isAuthorized("essentials.nocommandcost." + command))
- {
- return;
- }
-
- double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
+ final double mon = user.getMoney();
+ final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
{
- throw new Exception(Util.i18n("notEnoughMoney"));
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
user.takeMoney(cost);
}