diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-05-25 17:03:23 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-05-25 17:03:23 +0100 |
commit | 26ef8c062a07d7b8687c22175ae3855ad4b13b2a (patch) | |
tree | 9afc7c3c869d7bba5e0d51f8388bacc5e2f33eea | |
parent | e0c361ad07e35cc405d288e1de6ae691d82e4d2e (diff) | |
download | Essentials-26ef8c062a07d7b8687c22175ae3855ad4b13b2a.tar Essentials-26ef8c062a07d7b8687c22175ae3855ad4b13b2a.tar.gz Essentials-26ef8c062a07d7b8687c22175ae3855ad4b13b2a.tar.lz Essentials-26ef8c062a07d7b8687c22175ae3855ad4b13b2a.tar.xz Essentials-26ef8c062a07d7b8687c22175ae3855ad4b13b2a.zip |
Abort transaction before updating funds on balance overflow.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserData.java | 12 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandeco.java | 4 |
2 files changed, 10 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index c312fbe84..ee0650388 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -115,17 +115,19 @@ public abstract class UserData extends PlayerExtension implements IConf } public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException - { - money = value; + { BigDecimal maxMoney = ess.getSettings().getMaxMoney(); BigDecimal minMoney = ess.getSettings().getMinMoney(); - if (money.compareTo(maxMoney) > 0) - { - money = maxMoney; + if (value.compareTo(maxMoney) > 0) + { if (throwError) { throw new MaxMoneyException(); } + money = maxMoney; + } + else { + money = value; } if (money.compareTo(minMoney) < 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index 5efe54818..f589dcfed 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -105,8 +105,10 @@ public class Commandeco extends EssentialsLoopCommand private void set(BigDecimal amount, final User player, final CommandSource sender) throws MaxMoneyException { BigDecimal minBalance = ess.getSettings().getMinMoney(); + BigDecimal maxBalance = ess.getSettings().getMaxMoney(); boolean underMinimum = (amount.compareTo(minBalance) < 0); - player.setMoney(underMinimum ? minBalance : amount); + boolean aboveMax = (amount.compareTo(maxBalance) > 0); + player.setMoney(underMinimum ? minBalance : aboveMax ? maxBalance : amount); player.sendMessage(tl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess))); if (sender != null) { |