Skip to content

Commit

Permalink
Fixed detection of bank limits with bank interest not being correct (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Apr 8, 2022
1 parent fc14b51 commit f8140ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Expand Up @@ -38,6 +38,13 @@ public interface IslandBank {
*/
BankTransaction depositAdminMoney(CommandSender commandSender, BigDecimal amount);

/**
* Whether it's possible to deposit money into the bank without exceeding the bank limit.
*
* @param amount The amount of money to deposit.
*/
boolean canDepositMoney(BigDecimal amount);

/**
* Withdraw money from the bank.
*
Expand Down
Expand Up @@ -1691,7 +1691,7 @@ public boolean giveInterest(boolean checkOnlineOwner) {
BigDecimal balanceToGive = balance.multiply(new BigDecimal(BuiltinModules.BANK.bankInterestPercentage / 100D));

// If the money that will be given exceeds limit, we want to give money later.
if (balanceToGive.add(balance).compareTo(getBankLimit()) > 0) {
if (!islandBank.canDepositMoney(balanceToGive)) {
giveInterestFailed = true;
return false;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ public final class SIslandBank implements IslandBank {

private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();
private static final BigDecimal MONEY_FAILURE = BigDecimal.valueOf(-1);
private static final BigDecimal NO_BANK_LIMIT = BigDecimal.valueOf(-1);
private static final UUID CONSOLE_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");

private final AtomicReference<BigDecimal> balance = new AtomicReference<>(BigDecimal.ZERO);
Expand Down Expand Up @@ -88,8 +89,7 @@ public BankTransaction depositMoney(SuperiorPlayer superiorPlayer, BigDecimal am
failureReason = eventResult.getResult();
} else if (playerBalance.compareTo(amount) < 0) {
failureReason = "Not enough money";
} else if (island.getBankLimit().compareTo(BigDecimal.valueOf(-1)) > 0 &&
this.balance.get().add(amount).compareTo(island.getBankLimit()) > 0) {
} else if (!canDepositMoney(amount)) {
failureReason = "Exceed bank limit";
} else {
EconomyProvider.EconomyResult result = plugin.getProviders()
Expand Down Expand Up @@ -151,6 +151,13 @@ public BankTransaction depositAdminMoney(CommandSender commandSender, BigDecimal
return bankTransaction;
}

@Override
public boolean canDepositMoney(BigDecimal amount) {
Preconditions.checkNotNull(amount, "amount parameter cannot be null.");
return this.island.getBankLimit().compareTo(NO_BANK_LIMIT) <= 0 ||
this.balance.get().add(amount).compareTo(this.island.getBankLimit()) > 0;
}

@Override
public BankTransaction withdrawMoney(SuperiorPlayer superiorPlayer, BigDecimal amount, @Nullable List<String> commandsToExecute) {
Preconditions.checkNotNull(superiorPlayer, "superiorPlayer parameter cannot be null.");
Expand Down

0 comments on commit f8140ad

Please sign in to comment.