Skip to content

Commit c916082

Browse files
committed
Use max double instead of +∞ to avoid potential errors
1 parent 3a65fdd commit c916082

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/integrations/VaultIntegration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public boolean hasAccount(final @NotNull String player, final @NotNull String wo
119119
public double getBalance(final @NotNull OfflinePlayer player) {
120120
final @NotNull Optional<@NotNull Account> account = Account.getVaultAccount(player);
121121
return account.map(value -> Optional.ofNullable(value.balance).map(BigDecimal::doubleValue)
122-
.orElse(Double.POSITIVE_INFINITY)).orElse(0d);
122+
.orElse(Double.MAX_VALUE)).orElse(0d);
123123
}
124124

125125
/**
@@ -209,13 +209,13 @@ public boolean has(final @NotNull String player, final @NotNull String world, fi
209209
final @NotNull Optional<@NotNull Account> account = Account.getVaultAccount(player);
210210
if (account.isEmpty()) return new EconomyResponse(amount, 0, EconomyResponse.ResponseType.FAILURE, "Account not found");
211211
if (!account.get().hasFunds(BigDecimal.valueOf(amount)))
212-
return new EconomyResponse(amount, Optional.ofNullable(account.get().balance).map(BigDecimal::doubleValue).orElse(Double.POSITIVE_INFINITY), EconomyResponse.ResponseType.FAILURE, "Insufficient funds");
212+
return new EconomyResponse(amount, Optional.ofNullable(account.get().balance).map(BigDecimal::doubleValue).orElse(Double.MAX_VALUE), EconomyResponse.ResponseType.FAILURE, "Insufficient funds");
213213
final @NotNull Account serverAccount = Account.getServerAccount().orElse(new Account.ClosedAccount());
214214
// transfer funds to the server account since Vault just wants them "gone"
215215
account.get().transfer(serverAccount, BigDecimal.valueOf(amount), BankAccounts.getInstance().config().integrationsVaultDescription(), null);
216216
// remove funds from the server account without a transaction
217217
serverAccount.updateBalance(BigDecimal.valueOf(amount).negate());
218-
return new EconomyResponse(amount, Optional.ofNullable(account.get().balance).map(BigDecimal::doubleValue).orElse(Double.POSITIVE_INFINITY), EconomyResponse.ResponseType.SUCCESS, null);
218+
return new EconomyResponse(amount, Optional.ofNullable(account.get().balance).map(BigDecimal::doubleValue).orElse(Double.MAX_VALUE), EconomyResponse.ResponseType.SUCCESS, null);
219219
}
220220
/**
221221
* Remove amount of money from player.

0 commit comments

Comments
 (0)