mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Abort transaction before updating funds on balance overflow.
This commit is contained in:
parent
ada2fe01a2
commit
889dde7549
2 changed files with 10 additions and 6 deletions
|
@ -115,17 +115,19 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException
|
public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException
|
||||||
{
|
{
|
||||||
money = value;
|
|
||||||
BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
||||||
BigDecimal minMoney = ess.getSettings().getMinMoney();
|
BigDecimal minMoney = ess.getSettings().getMinMoney();
|
||||||
if (money.compareTo(maxMoney) > 0)
|
if (value.compareTo(maxMoney) > 0)
|
||||||
{
|
{
|
||||||
money = maxMoney;
|
|
||||||
if (throwError)
|
if (throwError)
|
||||||
{
|
{
|
||||||
throw new MaxMoneyException();
|
throw new MaxMoneyException();
|
||||||
}
|
}
|
||||||
|
money = maxMoney;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
money = value;
|
||||||
}
|
}
|
||||||
if (money.compareTo(minMoney) < 0)
|
if (money.compareTo(minMoney) < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,8 +105,10 @@ public class Commandeco extends EssentialsLoopCommand
|
||||||
private void set(BigDecimal amount, final User player, final CommandSource sender) throws MaxMoneyException
|
private void set(BigDecimal amount, final User player, final CommandSource sender) throws MaxMoneyException
|
||||||
{
|
{
|
||||||
BigDecimal minBalance = ess.getSettings().getMinMoney();
|
BigDecimal minBalance = ess.getSettings().getMinMoney();
|
||||||
|
BigDecimal maxBalance = ess.getSettings().getMaxMoney();
|
||||||
boolean underMinimum = (amount.compareTo(minBalance) < 0);
|
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)));
|
player.sendMessage(tl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||||
if (sender != null)
|
if (sender != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue