From 9196504c682179420e39be9cd5f58f07ee24685d Mon Sep 17 00:00:00 2001 From: meiamsome Date: Sat, 18 Aug 2012 21:53:01 +0200 Subject: [PATCH 1/3] 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. --- com/Acrobot/ChestShop/Economy/Economy.java | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/com/Acrobot/ChestShop/Economy/Economy.java b/com/Acrobot/ChestShop/Economy/Economy.java index 899756b..1ac8fda 100644 --- a/com/Acrobot/ChestShop/Economy/Economy.java +++ b/com/Acrobot/ChestShop/Economy/Economy.java @@ -17,42 +17,42 @@ public class Economy { return !p.isEmpty() && economy.hasAccount(uName.getName(p)); } + public static String serverAccount() { + return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); + } + + public static boolean isServerAccount(String acc) { + return serverAccount().equals(acc); + } + public static void add(String name, double amount) { - if (!hasAccount(name)) { - return; - } + Property taxAmount = isServerAccount(name) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT; - String serverAccount = Config.getString(Property.SERVER_ECONOMY_ACCOUNT); - Property taxAmount = name.equals(serverAccount) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT; - - if (Config.getFloat(taxAmount) != 0) { - double tax = getTax(taxAmount, amount); - if (!serverAccount.isEmpty()) { - economy.add(serverAccount, tax); + double tax = getTax(taxAmount, amount); + if(tax != 0) { + if (!serverAccount().isEmpty()) { + economy.add(serverAccount(), 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) { - return (Config.getFloat(tax) / 100F) * price; + return roundDown((Config.getFloat(tax) / 100F) * price); } public static void subtract(String name, double amount) { - if (!hasAccount(name)) { - return; - } - + if(name.isEmpty()) return; economy.subtract(uName.getName(name), roundUp(amount)); } public static boolean hasEnough(String name, double amount) { - if (!hasAccount(name)) { + if(isServerAccount(name)) { return true; } - return economy.hasEnough(uName.getName(name), roundUp(amount)); } From 80f658e748e82d7fba379e59a017f4aa8cb71d08 Mon Sep 17 00:00:00 2001 From: meiamsome Date: Sat, 18 Aug 2012 21:56:46 +0200 Subject: [PATCH 2/3] Added roundDown Added another round function as required. --- com/Acrobot/Breeze/Utils/NumberUtil.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/com/Acrobot/Breeze/Utils/NumberUtil.java b/com/Acrobot/Breeze/Utils/NumberUtil.java index 4a3f6f1..94b3f26 100644 --- a/com/Acrobot/Breeze/Utils/NumberUtil.java +++ b/com/Acrobot/Breeze/Utils/NumberUtil.java @@ -65,7 +65,7 @@ public class NumberUtil { } /** - * Rounds the number up to two digit points (Can be inaccurate due to using decimal-points) + * Rounds the number up to two decimal points (Can be inaccurate due to using decimal-points) * * @param number Number to round * @return Rounded number @@ -73,6 +73,15 @@ public class NumberUtil { public static double roundUp(double number) { return Math.ceil(number * 100) / 100; } + /** + * Rounds the number down to two decimal points + * + * @param number Number to round + * @return Rounded number + */ + public static double roundDown(double number) { + return Math.floor(number * 100) / 100; + } /** * Converts the number (in seconds) to timer-like format, like 2:00 (minutes:seconds) From 3e04048e67e9e67df1322b3e75816fcce806b80d Mon Sep 17 00:00:00 2001 From: meiamsome Date: Fri, 24 Aug 2012 17:36:35 +0200 Subject: [PATCH 3/3] Renamed serverAccount() to getServerAccountName() - --- com/Acrobot/ChestShop/Economy/Economy.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/com/Acrobot/ChestShop/Economy/Economy.java b/com/Acrobot/ChestShop/Economy/Economy.java index 1ac8fda..5d10dcd 100644 --- a/com/Acrobot/ChestShop/Economy/Economy.java +++ b/com/Acrobot/ChestShop/Economy/Economy.java @@ -17,26 +17,26 @@ public class Economy { return !p.isEmpty() && economy.hasAccount(uName.getName(p)); } - public static String serverAccount() { + public static String getServerAccountName() { return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); } public static boolean isServerAccount(String acc) { - return serverAccount().equals(acc); + return getServerAccountName().equals(acc); } public static void add(String name, double amount) { Property taxAmount = isServerAccount(name) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT; double tax = getTax(taxAmount, amount); - if(tax != 0) { + if (tax != 0) { if (!serverAccount().isEmpty()) { - economy.add(serverAccount(), tax); + economy.add(getServerAccountName(), tax); } amount -= tax; } - if(name.isEmpty()) return; + if (name.isEmpty()) return; economy.add(uName.getName(name), amount); } @@ -45,12 +45,12 @@ public class Economy { } public static void subtract(String name, double amount) { - if(name.isEmpty()) return; + if (name.isEmpty()) return; economy.subtract(uName.getName(name), roundUp(amount)); } public static boolean hasEnough(String name, double amount) { - if(isServerAccount(name)) { + if (isServerAccount(name)) { return true; } return economy.hasEnough(uName.getName(name), roundUp(amount));