mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-25 01:21:26 +01:00
Replace Reflection with setter implementation
This commit is contained in:
parent
d24fbc9f55
commit
c7000846cd
@ -16,8 +16,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
@ -1333,20 +1331,8 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
DecimalFormat currencyFormat = new DecimalFormat(currencyFormatString, decimalFormatSymbols);
|
||||
currencyFormat.setRoundingMode(RoundingMode.FLOOR);
|
||||
|
||||
// Updates NumberUtil#PRETTY_FORMAT field so that all of Essentials
|
||||
// can follow a single format.
|
||||
try {
|
||||
Field field = NumberUtil.class.getDeclaredField("PRETTY_FORMAT");
|
||||
field.setAccessible(true);
|
||||
field.set(null, currencyFormat);
|
||||
field.setAccessible(false);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
ess.getLogger().severe("Failed to apply custom currency format: " + e.getMessage());
|
||||
if (isDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Updates NumberUtil#PRETTY_FORMAT field so that all of Essentials can follow a single format.
|
||||
NumberUtil.internalSetPrettyFormat(currencyFormat);
|
||||
return currencyFormat;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
public class NumberUtil {
|
||||
|
||||
private static DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
|
||||
private static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
@ -30,6 +30,11 @@ public class NumberUtil {
|
||||
PRETTY_FORMAT.setMaximumFractionDigits(2);
|
||||
}
|
||||
|
||||
// this method should only be called by Essentials
|
||||
public static void internalSetPrettyFormat(NumberFormat prettyFormat) {
|
||||
PRETTY_FORMAT = prettyFormat;
|
||||
}
|
||||
|
||||
public static String shortCurrency(final BigDecimal value, final IEssentials ess) {
|
||||
return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user