diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index c4c273221..14f60d745 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -89,12 +89,12 @@ public abstract class UserData extends PlayerExtension implements IConf public void setMoney(double value) { - money = value; + money = Util.sanitizeMoney(value); if (Math.abs(money) > ess.getSettings().getMaxMoney()) { money = money < 0 ? -ess.getSettings().getMaxMoney() : ess.getSettings().getMaxMoney(); } - config.setProperty("money", value); + config.setProperty("money", money); config.save(); } private Map homes; @@ -122,11 +122,11 @@ public abstract class UserData extends PlayerExtension implements IConf } return search; } - + public Location getHome(String name) throws Exception { String search = getHomeName(name); - return config.getLocation("homes." + search, getServer()); + return config.getLocation("homes." + search, getServer()); } public Location getHome(final Location world) @@ -318,7 +318,6 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("lastlocation", loc); config.save(); } - private Location logoutLocation; private Location _getLogoutLocation() @@ -337,7 +336,7 @@ public abstract class UserData extends PlayerExtension implements IConf { return logoutLocation; } - + public void setLogoutLocation(Location loc) { if (loc == null || loc.getWorld() == null) @@ -348,7 +347,6 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("logoutlocation", loc); config.save(); } - private long lastTeleportTimestamp; private long _getLastTeleportTimestamp() @@ -549,7 +547,7 @@ public abstract class UserData extends PlayerExtension implements IConf { return config.getBoolean("muted", false); } - + public boolean getMuted() { return muted; @@ -825,10 +823,10 @@ public abstract class UserData extends PlayerExtension implements IConf return config.getBoolean("powertoolsenabled", true); } private Map kitTimestamps; - + private Map _getKitTimestamps() { - + if (config.isConfigurationSection("timestamps.kits")) { final ConfigurationSection section = config.getConfigurationSection("timestamps.kits"); @@ -848,7 +846,7 @@ public abstract class UserData extends PlayerExtension implements IConf } return new HashMap(); } - + public long getKitTimestamp(String name) { name = name.replace('.', '_').replace('/', '_'); @@ -867,32 +865,32 @@ public abstract class UserData extends PlayerExtension implements IConf } public void setConfigProperty(String node, Object object) - { - final String prefix = "info."; - node = prefix+node; - if (object instanceof Map) - { - config.setProperty(node, (Map) object); - } - else if (object instanceof List) - { - config.setProperty(node, (List) object); - } - else if (object instanceof Location) - { - config.setProperty(node, (Location) object); - } - else if (object instanceof ItemStack) - { - config.setProperty(node, (ItemStack) object); - } - else - { - config.setProperty(node, object); - } - config.save(); - } - + { + final String prefix = "info."; + node = prefix + node; + if (object instanceof Map) + { + config.setProperty(node, (Map)object); + } + else if (object instanceof List) + { + config.setProperty(node, (List)object); + } + else if (object instanceof Location) + { + config.setProperty(node, (Location)object); + } + else if (object instanceof ItemStack) + { + config.setProperty(node, (ItemStack)object); + } + else + { + config.setProperty(node, object); + } + config.save(); + } + public Set getConfigKeys() { if (config.isConfigurationSection("info")) @@ -901,7 +899,7 @@ public abstract class UserData extends PlayerExtension implements IConf } return new HashSet(); } - + public Map getConfigMap() { if (config.isConfigurationSection("info")) @@ -910,16 +908,16 @@ public abstract class UserData extends PlayerExtension implements IConf } return new HashMap(); } - + public Map getConfigMap(String node) { - if (config.isConfigurationSection("info."+node)) + if (config.isConfigurationSection("info." + node)) { - return config.getConfigurationSection("info."+node).getValues(true); + return config.getConfigurationSection("info." + node).getValues(true); } return new HashMap(); } - + public void save() { config.save(); diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 677aa230f..879816ce8 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -1,6 +1,8 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import java.math.BigDecimal; +import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -521,12 +523,19 @@ public class Util } return is; } + + public static double sanitizeMoney(final double value) + { + BigDecimal money = new BigDecimal(value, MathContext.DECIMAL128); + return money.doubleValue(); + } private static DecimalFormat dFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US)); public static String formatAsCurrency(final double value) { + double fvalue = sanitizeMoney(value); dFormat.setRoundingMode(RoundingMode.FLOOR); - String str = dFormat.format(value); + String str = dFormat.format(fvalue); if (str.endsWith(".00")) { str = str.substring(0, str.length() - 3); @@ -714,10 +723,11 @@ public class Util return pattern.matcher(input).replaceAll("\u00a7$1"); } private static final Pattern IPPATTERN = Pattern.compile( - "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + - "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); - - public static boolean validIP(String ipAddress) { + "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); + + public static boolean validIP(String ipAddress) + { return IPPATTERN.matcher(ipAddress).matches(); } }