Added Economy option.

This commit is contained in:
Brianna 2019-12-28 15:21:43 -05:00
parent 288eae8f47
commit 2ea41e962d
5 changed files with 39 additions and 1 deletions

View File

@ -61,6 +61,19 @@ public class EconomyManager {
return manager.isEnabled() ? manager.getCurrentHook().formatEconomy(amt) : String.valueOf(amt);
}
/**
* Get the players available balance
*
* @param player player
* @return the amount of available balance
*/
public static double getBalance(OfflinePlayer player) {
if (!manager.isEnabled())
return 0;
return manager.getCurrentHook().getBalance(player);
}
/**
* Check to see if a player has at least some balance available. <br />
* NOTE: using a default economy assumes that this library is shaded

View File

@ -6,6 +6,14 @@ import org.bukkit.OfflinePlayer;
public abstract class Economy implements Hook {
/**
* Get the players available balance
*
* @param player player
* @return the amount of available balance
*/
public abstract double getBalance(OfflinePlayer player);
/**
* Check to see if a player has at least some balance available
*

View File

@ -26,6 +26,11 @@ public class PlayerPointsEconomy extends Economy {
return "PlayerPoints";
}
@Override
public double getBalance(OfflinePlayer player) {
return playerPoints.getAPI().look(player.getUniqueId());
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);

View File

@ -30,6 +30,11 @@ public class ReserveEconomy extends Economy {
return economyAPI.format(BigDecimal.valueOf(amt));
}
@Override
public double getBalance(OfflinePlayer player) {
return economyAPI.getBankHoldings(player.getUniqueId()).doubleValue();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost));

View File

@ -9,7 +9,7 @@ public class VaultEconomy extends Economy {
private final net.milkbowl.vault.economy.Economy vault;
public VaultEconomy() {
// this returns null if we have Vault with no compatibe eco plugin
// this returns null if we have Vault with no compatible eco plugin
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> v = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if(v != null) {
this.vault = v.getProvider();
@ -34,6 +34,13 @@ public class VaultEconomy extends Economy {
return vault != null ? vault.format(amt) : super.formatEconomy(amt);
}
@Override
public double getBalance(OfflinePlayer player) {
if (vault == null)
return 0;
return vault.getBalance(player);
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return vault != null && vault.has(player, cost);