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 40d601f7..e78e3367 100644 --- a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java @@ -3,11 +3,15 @@ package com.songoda.core.hooks; import com.songoda.core.hooks.economies.Economy; import org.bukkit.OfflinePlayer; +import java.text.DecimalFormat; + /** * A convenience class for static access to an Economy HookManager */ public class EconomyManager { + private static String currencySymbol = "$"; + private static final HookManager manager = new HookManager(Economy.class); /** @@ -58,8 +62,9 @@ public class EconomyManager { * @param amt amount to display * @return a currency string as formatted by the economy plugin */ - public static String formatEconomy(double amt) { - return manager.isEnabled() ? manager.getCurrentHook().formatEconomy(amt) : String.valueOf(amt); + public String formatEconomy(double amt) { + DecimalFormat formatter = new DecimalFormat(amt == Math.ceil(amt) ? "#,###" : "#,###.00"); + return currencySymbol + formatter.format(amt); } /** @@ -110,4 +115,13 @@ public class EconomyManager { public static boolean deposit(OfflinePlayer player, double amount) { return manager.isEnabled() && manager.getCurrentHook().deposit(player, amount); } + + /** + * Change the curency symbl used in the #formatEconomy method. + * + * @param currencySymbol the new symbol + */ + public static void setCurrencySymbol(String currencySymbol) { + EconomyManager.currencySymbol = currencySymbol; + } } 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 5b0ab864..a9739310 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 @@ -41,15 +41,4 @@ public abstract class Economy implements Hook { * @return true if the total amount was added successfully */ public abstract boolean deposit(OfflinePlayer player, double amount); - - /** - * Format the given amount to a human-readable string in this currency - * - * @param amt amount to display - * @return a currency string as formatted by the economy plugin - */ - public String formatEconomy(double amt) { - DecimalFormat formatter = new DecimalFormat(amt == Math.ceil(amt) ? "#,###" : "#,###.00"); - return "$" + formatter.format(amt); - } } 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 a2483dea..754ed78d 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 @@ -25,11 +25,6 @@ public class ReserveEconomy extends Economy { return "Reserve"; } - @Override - public String formatEconomy(double amt) { - return economyAPI.format(BigDecimal.valueOf(amt)); - } - @Override public double getBalance(OfflinePlayer player) { return economyAPI.getBankHoldings(player.getUniqueId()).doubleValue(); 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 79f88e17..0a3acda0 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 @@ -29,11 +29,6 @@ public class VaultEconomy extends Economy { return "Vault"; } - @Override - public String formatEconomy(double amt) { - return vault != null ? vault.format(amt) : super.formatEconomy(amt); - } - @Override public double getBalance(OfflinePlayer player) { if (vault == null)