Merge remote-tracking branch 'games647/java9' into 1.13

This commit is contained in:
md678685 2018-10-31 14:53:49 +00:00
commit ba959586e2
3 changed files with 11 additions and 47 deletions

View File

@ -17,8 +17,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;
@ -1352,24 +1350,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 modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, currencyFormat);
modifiersField.setAccessible(false);
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;
}

View File

@ -11,14 +11,14 @@ import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
public class NumberUtil {
static DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
private static DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
private static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
// This field is likely to be modified in com.earth2me.essentials.Settings when loading currency format.
// This ensures that we can supply a constant formatting.
static final NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
private static NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
static {
twoDPlaces.setRoundingMode(RoundingMode.HALF_UP);
@ -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);
}

23
pom.xml
View File

@ -84,29 +84,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>