Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/main/java/ca/tweetzy/funds/hooks/VaultHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
if (account == null || currency == null)
return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Funds vault currency not set or user account not found!");

if (account.getCurrencies().get(currency) < amount) {
return new EconomyResponse(0D, account.getCurrencies().get(currency), EconomyResponse.ResponseType.FAILURE, null);
final double currentBalance = account.getCurrencies().getOrDefault(currency, 0D);
if (currentBalance < amount) {
return new EconomyResponse(0D, currentBalance, EconomyResponse.ResponseType.FAILURE, null);
}

final double currentBalance = account.getCurrencies().get(currency);
account.getCurrencies().put(currency, currentBalance - amount);
account.sync(true);

return new EconomyResponse(amount, account.getCurrencies().get(currency), EconomyResponse.ResponseType.SUCCESS, null);
return new EconomyResponse(amount, currentBalance, EconomyResponse.ResponseType.SUCCESS, null);
}

@Override
Expand All @@ -172,15 +172,15 @@ public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (account == null || currency == null)
return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Funds vault currency not set or user account not found!");

if (account.getCurrencies().get(currency) < amount) {
return new EconomyResponse(0D, account.getCurrencies().get(currency), EconomyResponse.ResponseType.FAILURE, null);
final double currentBalance = account.getCurrencies().getOrDefault(currency, 0D);
if (currentBalance < amount) {
return new EconomyResponse(0D, currentBalance, EconomyResponse.ResponseType.FAILURE, null);
}

final double currentBalance = account.getCurrencies().get(currency);
account.getCurrencies().put(currency, currentBalance - amount);
account.sync(true);

return new EconomyResponse(amount, account.getCurrencies().get(currency), EconomyResponse.ResponseType.SUCCESS, null);
return new EconomyResponse(amount, currentBalance, EconomyResponse.ResponseType.SUCCESS, null);
}

@Override
Expand All @@ -198,11 +198,11 @@ public EconomyResponse depositPlayer(OfflinePlayer player, double amount) {
return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Funds vault currency not set or user account not found!");


final double currentBalance = account.getCurrencies().get(currency);
final double currentBalance = account.getCurrencies().getOrDefault(currency, 0D);
account.getCurrencies().put(currency, currentBalance + amount);
account.sync(true);

return new EconomyResponse(amount, account.getCurrencies().get(currency), EconomyResponse.ResponseType.SUCCESS, null);
return new EconomyResponse(amount, currentBalance, EconomyResponse.ResponseType.SUCCESS, null);
}

@Override
Expand All @@ -219,11 +219,11 @@ public EconomyResponse depositPlayer(String playerName, double amount) {
return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Funds vault currency not set or user account not found!");


final double currentBalance = account.getCurrencies().get(currency);
final double currentBalance = account.getCurrencies().getOrDefault(currency, 0D);
account.getCurrencies().put(currency, currentBalance + amount);
account.sync(true);

return new EconomyResponse(amount, account.getCurrencies().get(currency), EconomyResponse.ResponseType.SUCCESS, null);
return new EconomyResponse(amount, currentBalance, EconomyResponse.ResponseType.SUCCESS, null);
}

@Override
Expand Down