Skip to content

Commit

Permalink
Fixed checking for error message in Vault support even if the transac…
Browse files Browse the repository at this point in the history
…tion was successful (#1836)
  • Loading branch information
OmerBenGera committed Aug 10, 2023
1 parent 9d27c01 commit 81e2a69
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.RoundingMode;

Expand Down Expand Up @@ -44,7 +45,7 @@ public EconomyResult depositMoney(SuperiorPlayer superiorPlayer, double amount)
EconomyResponse economyResponse = econ.depositPlayer(offlinePlayer, amount);
double moneyInTransaction = Precision.round(getMoneyInBank(offlinePlayer) - moneyBeforeDeposit, 3);

String errorMessage = moneyInTransaction == amount ? economyResponse.errorMessage :
String errorMessage = moneyInTransaction == amount ? getErrorMessageFromResponse(economyResponse) :
moneyInTransaction == 0 ? "You have exceed the limit of your bank" : "";

return new EconomyResult(errorMessage, moneyInTransaction);
Expand All @@ -58,7 +59,7 @@ public EconomyResult withdrawMoney(SuperiorPlayer superiorPlayer, double amount)
EconomyResponse economyResponse = econ.withdrawPlayer(offlinePlayer, amount);
double moneyInTransaction = Precision.round(moneyBeforeWithdraw - getMoneyInBank(offlinePlayer), 3);

String errorMessage = moneyInTransaction == amount ? economyResponse.errorMessage :
String errorMessage = moneyInTransaction == amount ? getErrorMessageFromResponse(economyResponse) :
moneyInTransaction == 0 ? "Couldn't process the transaction" : "";

return new EconomyResult(errorMessage, moneyInTransaction);
Expand All @@ -71,4 +72,9 @@ private double getMoneyInBank(OfflinePlayer offlinePlayer) {
return Precision.round(econ.getBalance(offlinePlayer), 3);
}

@Nullable
private static String getErrorMessageFromResponse(EconomyResponse economyResponse) {
return economyResponse.transactionSuccess() ? null : economyResponse.errorMessage;
}

}

0 comments on commit 81e2a69

Please sign in to comment.