prevent essentials from having a race condition with NPC accounts.

This commit is contained in:
Nick Minkler 2019-04-28 12:30:47 -07:00
parent afaaf0d9f7
commit 19f0d8a3fe
2 changed files with 15 additions and 8 deletions

View File

@ -12,7 +12,7 @@
<!-- Project information --> <!-- Project information -->
<groupId>net.milkbowl.vault</groupId> <groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId> <artifactId>Vault</artifactId>
<version>${api.version}.1</version> <version>${api.version}.2</version>
<name>Vault</name> <name>Vault</name>
<url>https://dev.bukkit.org/projects/vault</url> <url>https://dev.bukkit.org/projects/vault</url>
<description>Vault is a Permissions &amp; Economy API to allow plugins to more easily hook into these systems without needing to hook each individual system themselves. <description>Vault is a Permissions &amp; Economy API to allow plugins to more easily hook into these systems without needing to hook each individual system themselves.

View File

@ -132,11 +132,13 @@ public class Economy_Essentials extends AbstractEconomy {
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
@Override public EconomyResponse tryDepositPlayer(String playerName, double amount, int tries) {
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) { if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
} }
if (tries <= 0) {
return new EconomyResponse(amount, 0, ResponseType.FAILURE, "Failed to deposit amount.");
}
double balance; double balance;
EconomyResponse.ResponseType type; EconomyResponse.ResponseType type;
@ -145,26 +147,26 @@ public class Economy_Essentials extends AbstractEconomy {
try { try {
com.earth2me.essentials.api.Economy.add(playerName, amount); com.earth2me.essentials.api.Economy.add(playerName, amount);
balance = com.earth2me.essentials.api.Economy.getMoney(playerName); balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS; type = ResponseType.SUCCESS;
} catch (UserDoesNotExistException e) { } catch (UserDoesNotExistException e) {
if (createPlayerAccount(playerName)) { if (createPlayerAccount(playerName)) {
return depositPlayer(playerName, amount); return tryDepositPlayer(playerName, amount, tries--);
} else { } else {
amount = 0; amount = 0;
balance = 0; balance = 0;
type = EconomyResponse.ResponseType.FAILURE; type = ResponseType.FAILURE;
errorMessage = "User does not exist"; errorMessage = "User does not exist";
} }
} catch (NoLoanPermittedException e) { } catch (NoLoanPermittedException e) {
try { try {
balance = com.earth2me.essentials.api.Economy.getMoney(playerName); balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
amount = 0; amount = 0;
type = EconomyResponse.ResponseType.FAILURE; type = ResponseType.FAILURE;
errorMessage = "Loan was not permitted"; errorMessage = "Loan was not permitted";
} catch (UserDoesNotExistException e1) { } catch (UserDoesNotExistException e1) {
balance = 0; balance = 0;
amount = 0; amount = 0;
type = EconomyResponse.ResponseType.FAILURE; type = ResponseType.FAILURE;
errorMessage = "Loan was not permitted"; errorMessage = "Loan was not permitted";
} }
} }
@ -172,6 +174,11 @@ public class Economy_Essentials extends AbstractEconomy {
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
return tryDepositPlayer(playerName, amount, 2);
}
public class EconomyServerListener implements Listener { public class EconomyServerListener implements Listener {
Economy_Essentials economy = null; Economy_Essentials economy = null;