mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-26 03:55:46 +01:00
Remove addBalance and subtractBalance methods from storage backends.
This commit is contained in:
parent
86946f2e60
commit
5702c1ed5c
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user