cleaned up BOSE7 implementation a bit

This commit is contained in:
Sleaker 2012-03-15 07:27:51 -07:00
parent e1d28d1a7f
commit 045c322af7

View File

@ -79,68 +79,34 @@ public class Economy_BOSE7 implements Economy {
@Override @Override
public EconomyResponse withdrawPlayer(String playerName, double amount) { public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if (amount < 0) { if (amount < 0) {
errorMessage = "Cannot withdraw negative funds"; return new EconomyResponse(0, economy.getPlayerMoneyDouble(playerName), ResponseType.FAILURE, "Cannot withdraw negative funds");
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = economy.getPlayerMoneyDouble(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} }
balance = economy.getPlayerMoneyDouble(playerName); if (!has(playerName, amount)) {
if (balance - amount < 0) { return new EconomyResponse(0, economy.getPlayerMoneyDouble(playerName), ResponseType.FAILURE, "Insufficient funds");
errorMessage = "Insufficient funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
return new EconomyResponse(amount, balance, type, errorMessage);
} }
double balance = economy.getPlayerMoneyDouble(playerName);
if (economy.setPlayerMoney(playerName, balance - amount, false)) { if (economy.setPlayerMoney(playerName, balance - amount, false)) {
type = EconomyResponse.ResponseType.SUCCESS;
balance = economy.getPlayerMoneyDouble(playerName); balance = economy.getPlayerMoneyDouble(playerName);
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
return new EconomyResponse(amount, balance, type, errorMessage);
} else { } else {
errorMessage = "Error withdrawing funds"; return new EconomyResponse(0, balance, ResponseType.FAILURE, "Error withdrawing funds");
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = economy.getPlayerMoneyDouble(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }
@Override @Override
public EconomyResponse depositPlayer(String playerName, double amount) { public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if (amount < 0) { if (amount < 0) {
errorMessage = "Cannot deposit negative funds"; return new EconomyResponse(0, economy.getPlayerMoneyDouble(playerName), ResponseType.FAILURE, "Cannot deposit negative funds");
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
return new EconomyResponse(amount, economy.getPlayerMoneyDouble(playerName), type, errorMessage);
} }
balance = economy.getPlayerMoneyDouble(playerName); double balance = economy.getPlayerMoneyDouble(playerName);
if (economy.setPlayerMoney(playerName, balance + amount, false)) { if (economy.setPlayerMoney(playerName, balance + amount, false)) {
type = EconomyResponse.ResponseType.SUCCESS;
balance = economy.getPlayerMoneyDouble(playerName); balance = economy.getPlayerMoneyDouble(playerName);
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
return new EconomyResponse(amount, balance, type, errorMessage);
} else { } else {
errorMessage = "Error withdrawing funds"; return new EconomyResponse(0, balance, ResponseType.FAILURE, "Error depositing funds");
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = economy.getPlayerMoneyDouble(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }