diff --git a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java index e2a6dc0f..a09c00af 100644 --- a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java @@ -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.
* NOTE: using a default economy assumes that this library is shaded diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java index 7c304f7e..54d7e03d 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java @@ -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 * diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java index 8856ebb2..98dbf3c2 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java @@ -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); diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java index 93a9788d..a2483dea 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java @@ -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)); diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java index 2726a2ec..684619c5 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java @@ -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 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);