Remove addBalance and subtractBalance methods from storage backends.

This commit is contained in:
AppleDash 2016-07-12 12:22:12 -04:00
parent 86946f2e60
commit 5702c1ed5c
4 changed files with 13 additions and 61 deletions

View File

@ -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;
}
/**

View File

@ -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.

View File

@ -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<UUID, Double> getTopBalances(int amount) {
return MapUtil.takeFromMap(topBalances, amount);

View File

@ -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<UUID, Double> getTopBalances(int amount) {
return MapUtil.takeFromMap(topBalances, amount);