mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 09:59:49 -05:00
Lazy initialize decimalFormat value, fix format issue
This commit is contained in:
1 parent
ca35ea4fb3
commit
116d4d56a1
1 file changed
+11
-10
@@ -68,7 +68,7 @@ public class MsgUtil {
|
||||
private static final String invaildMsg = "Invaild message";
|
||||
|
||||
private static final Map<UUID, List<TransactionMessage>> outGoingPlayerMessages = Maps.newConcurrentMap();
|
||||
private static final DecimalFormat decimalFormat = processFormat();
|
||||
private static DecimalFormat decimalFormat;
|
||||
public static GameLanguage gameLanguage;
|
||||
private static QuickShop plugin = QuickShop.getInstance();
|
||||
@Getter
|
||||
@@ -82,15 +82,6 @@ public class MsgUtil {
|
||||
private static JsonConfiguration builtInLang;
|
||||
private static JsonConfiguration builtInOriginalLang;
|
||||
|
||||
private static DecimalFormat processFormat() {
|
||||
try {
|
||||
return new DecimalFormat(Objects.requireNonNull(QuickShop.getInstance().getConfig().getString("decimal-format")));
|
||||
} catch (Exception e) {
|
||||
QuickShop.getInstance().getLogger().log(Level.WARNING, "Error when processing decimal format, using system default: " + e.getMessage());
|
||||
return new DecimalFormat();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes any messages that are older than a week in the database, to save on space.
|
||||
*/
|
||||
@@ -770,6 +761,16 @@ public class MsgUtil {
|
||||
}
|
||||
|
||||
public static String decimalFormat(double value) {
|
||||
if (decimalFormat == null) {
|
||||
//lazy initialize
|
||||
try {
|
||||
String format = plugin.getConfig().getString("decimal-format");
|
||||
decimalFormat = format == null ? new DecimalFormat() : new DecimalFormat(format);
|
||||
} catch (Exception e) {
|
||||
QuickShop.getInstance().getLogger().log(Level.WARNING, "Error when processing decimal format, using system default: " + e.getMessage());
|
||||
decimalFormat = new DecimalFormat();
|
||||
}
|
||||
}
|
||||
return decimalFormat.format(value);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user