diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/EconomyManager.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/EconomyManager.java index 605b65e..3f21f8e 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/EconomyManager.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/EconomyManager.java @@ -85,7 +85,11 @@ public class EconomyManager { throw new IllegalArgumentException("Cannot add a negative amount!"); } - return backend.addBalance(targetPlayer, amount); + double newAmount = backend.getBalance(targetPlayer) + amount; + + backend.setBalance(targetPlayer, newAmount); + + return newAmount; } /** @@ -103,13 +107,17 @@ public class EconomyManager { throw new IllegalArgumentException("Cannot subtract a negative amount!"); } + double newAmount = backend.getBalance(targetPlayer) - amount; + + /* Subtracting that much would result in a negative balance - don't do that */ - if (backend.getBalance(targetPlayer) - amount <= 0.0D) { - backend.setBalance(targetPlayer, 0.0D); - return 0.0D; + if (newAmount <= 0.0D) { + newAmount = 0.0D; } - return backend.subtractBalance(targetPlayer, amount); + backend.setBalance(targetPlayer, newAmount); + + return newAmount; } /** diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/EconomyStorageBackend.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/EconomyStorageBackend.java index 6e57b67..54ea58c 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/EconomyStorageBackend.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/EconomyStorageBackend.java @@ -33,22 +33,6 @@ public interface EconomyStorageBackend { */ void setBalance(OfflinePlayer player, double newBalance); - /** - * Add to a player's balance. - * @param player Player - * @param amount Amount to add to the balance - * @return Player's new balance - */ - double addBalance(OfflinePlayer player, double amount); - - /** - * Subtract from a player's balance. - * @param player Player - * @param amount Amount to subtract from the balance - * @return Player's new balance - */ - double subtractBalance(OfflinePlayer player, double amount); - /** * Get the UUIDs of the players who have the most money, along with how much money they have. * @param amount Maximum number to get. diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java index 9ead866..0c5f14c 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java @@ -90,24 +90,6 @@ public class EconomyStorageBackendFlatfile implements EconomyStorageBackend { saveDatabase(); } - @Override - public synchronized double addBalance(OfflinePlayer player, double amount) { - double newAmount = getBalance(player) + amount; - - setBalance(player, newAmount); - - return newAmount; - } - - @Override - public synchronized double subtractBalance(OfflinePlayer player, double amount) { - double newAmount = getBalance(player) - amount; - - setBalance(player, newAmount); - - return newAmount; - } - @Override public Map getTopBalances(int amount) { return MapUtil.takeFromMap(topBalances, amount); diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java index 78bfcd5..0134432 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java @@ -126,28 +126,6 @@ public class EconomyStorageBackendMySQL implements EconomyStorageBackend { }); } - @Override - public synchronized double addBalance(OfflinePlayer player, double amount) { - // TODO: Optimize? - double curBalance = getBalance(player); - double newBalance = curBalance + amount; - - setBalance(player, newBalance); - - return newBalance; - } - - @Override - public synchronized double subtractBalance(OfflinePlayer player, double amount) { - // TODO: Optimize? - double curBalance = getBalance(player); - double newBalance = curBalance - amount; - - setBalance(player, newBalance); - - return newBalance; - } - @Override public Map getTopBalances(int amount) { return MapUtil.takeFromMap(topBalances, amount);