fix CurrencyCore bankBalance method, simplified some code in iCo6

This commit is contained in:
Sleaker 2011-12-31 16:02:21 -08:00
parent 062c0ee12b
commit 9406183409
2 changed files with 10 additions and 12 deletions

View File

@ -111,9 +111,10 @@ public class Economy_CurrencyCore implements Economy {
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
} else if (!account.hasBalance(amount)) {
return new EconomyResponse(0.0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds");
} else {
account.subtractBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
account.subtractBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
@Override
@ -137,11 +138,12 @@ public class Economy_CurrencyCore implements Economy {
@Override
public EconomyResponse bankBalance(String name) {
if (this.currency.getAccountManager().hasAccount(name)) {
return new EconomyResponse(0, getBalance(name), ResponseType.FAILURE, "That account already exists.");
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exists.");
}
this.currency.getAccountManager().createAccount(name);
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, "");
}
@Override

View File

@ -132,16 +132,12 @@ public class Economy_iConomy6 implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
Account account = accounts.get(playerName);
Holdings holdings = account.getHoldings();
Holdings holdings = accounts.get(playerName).getHoldings();
holdings.add(amount);
balance = holdings.getBalance();
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(amount, balance, type, errorMessage);
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null);
}
@Override