Fixed some potential bugs.

Removed a hasAccount check from add, subtract and hasEnough. These checks should not exist.
The reasons are:
hasEnough: The default for an account may not have enough to pay for anything. Changed to check if Server Account instead.
add & subtract: Changed the check to only isEmpty. This is because money should not just be created or destroyed.
This commit is contained in:
meiamsome 2012-08-18 21:53:01 +02:00
parent af692eb4f8
commit 9196504c68

View File

@ -17,42 +17,42 @@ public class Economy {
return !p.isEmpty() && economy.hasAccount(uName.getName(p)); return !p.isEmpty() && economy.hasAccount(uName.getName(p));
} }
public static void add(String name, double amount) { public static String serverAccount() {
if (!hasAccount(name)) { return Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
return;
} }
String serverAccount = Config.getString(Property.SERVER_ECONOMY_ACCOUNT); public static boolean isServerAccount(String acc) {
Property taxAmount = name.equals(serverAccount) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT; return serverAccount().equals(acc);
}
public static void add(String name, double amount) {
Property taxAmount = isServerAccount(name) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT;
if (Config.getFloat(taxAmount) != 0) {
double tax = getTax(taxAmount, amount); double tax = getTax(taxAmount, amount);
if (!serverAccount.isEmpty()) { if(tax != 0) {
economy.add(serverAccount, tax); if (!serverAccount().isEmpty()) {
economy.add(serverAccount(), tax);
} }
amount -= tax; amount -= tax;
} }
economy.add(uName.getName(name), roundUp(amount)); if(name.isEmpty()) return;
economy.add(uName.getName(name), amount);
} }
public static double getTax(Property tax, double price) { public static double getTax(Property tax, double price) {
return (Config.getFloat(tax) / 100F) * price; return roundDown((Config.getFloat(tax) / 100F) * price);
} }
public static void subtract(String name, double amount) { public static void subtract(String name, double amount) {
if (!hasAccount(name)) { if(name.isEmpty()) return;
return;
}
economy.subtract(uName.getName(name), roundUp(amount)); economy.subtract(uName.getName(name), roundUp(amount));
} }
public static boolean hasEnough(String name, double amount) { public static boolean hasEnough(String name, double amount) {
if (!hasAccount(name)) { if(isServerAccount(name)) {
return true; return true;
} }
return economy.hasEnough(uName.getName(name), roundUp(amount)); return economy.hasEnough(uName.getName(name), roundUp(amount));
} }