mirror of
https://github.com/MilkBowl/Vault.git
synced 2025-01-13 03:40:38 +01:00
prevent essentials from having a race condition with NPC accounts.
This commit is contained in:
parent
afaaf0d9f7
commit
19f0d8a3fe
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
||||
<!-- Project information -->
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>${api.version}.1</version>
|
||||
<version>${api.version}.2</version>
|
||||
<name>Vault</name>
|
||||
<url>https://dev.bukkit.org/projects/vault</url>
|
||||
<description>Vault is a Permissions & Economy API to allow plugins to more easily hook into these systems without needing to hook each individual system themselves.
|
||||
|
@ -132,11 +132,13 @@ public class Economy_Essentials extends AbstractEconomy {
|
||||
return new EconomyResponse(amount, balance, type, errorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse depositPlayer(String playerName, double amount) {
|
||||
public EconomyResponse tryDepositPlayer(String playerName, double amount, int tries) {
|
||||
if (amount < 0) {
|
||||
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;
|
||||
EconomyResponse.ResponseType type;
|
||||
@ -145,26 +147,26 @@ public class Economy_Essentials extends AbstractEconomy {
|
||||
try {
|
||||
com.earth2me.essentials.api.Economy.add(playerName, amount);
|
||||
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
|
||||
type = EconomyResponse.ResponseType.SUCCESS;
|
||||
type = ResponseType.SUCCESS;
|
||||
} catch (UserDoesNotExistException e) {
|
||||
if (createPlayerAccount(playerName)) {
|
||||
return depositPlayer(playerName, amount);
|
||||
return tryDepositPlayer(playerName, amount, tries--);
|
||||
} else {
|
||||
amount = 0;
|
||||
balance = 0;
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
type = ResponseType.FAILURE;
|
||||
errorMessage = "User does not exist";
|
||||
}
|
||||
} catch (NoLoanPermittedException e) {
|
||||
try {
|
||||
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
|
||||
amount = 0;
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
type = ResponseType.FAILURE;
|
||||
errorMessage = "Loan was not permitted";
|
||||
} catch (UserDoesNotExistException e1) {
|
||||
balance = 0;
|
||||
amount = 0;
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
type = ResponseType.FAILURE;
|
||||
errorMessage = "Loan was not permitted";
|
||||
}
|
||||
}
|
||||
@ -172,6 +174,11 @@ public class Economy_Essentials extends AbstractEconomy {
|
||||
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 {
|
||||
Economy_Essentials economy = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user