Economy Madness

This commit is contained in:
KHobbits 2013-05-05 04:13:17 +01:00
parent 801acbb004
commit 2d70bb19f7
21 changed files with 216 additions and 157 deletions

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.signs.EssentialsSign; import com.earth2me.essentials.signs.EssentialsSign;
import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.IText;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,9 +31,9 @@ public interface ISettings extends IConf
int getChatRadius(); int getChatRadius();
double getCommandCost(IEssentialsCommand cmd); BigDecimal getCommandCost(IEssentialsCommand cmd);
double getCommandCost(String label); BigDecimal getCommandCost(String label);
String getCurrencySymbol(); String getCurrencySymbol();
@ -110,9 +111,9 @@ public interface ISettings extends IConf
boolean warnOnSmite(); boolean warnOnSmite();
double getMaxMoney(); BigDecimal getMaxMoney();
double getMinMoney(); BigDecimal getMinMoney();
boolean isEcoLogEnabled(); boolean isEcoLogEnabled();

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand;
import java.math.BigDecimal;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
@ -23,13 +24,13 @@ public interface IUser extends Player
Player getBase(); Player getBase();
double getMoney(); BigDecimal getMoney();
void takeMoney(double value); void takeMoney(BigDecimal value);
void giveMoney(double value); void giveMoney(BigDecimal value);
boolean canAfford(double value); boolean canAfford(BigDecimal value);
String getGroup(); String getGroup();

View file

@ -7,6 +7,7 @@ import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.SimpleTextInput;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -31,8 +32,8 @@ public class Kit
else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH)))
{ {
String cost = ""; String cost = "";
Double costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user); BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
if (costPrice > 0d) if (costPrice.compareTo(BigDecimal.ZERO) > 0)
{ {
cost = _("kitCost", Util.displayCurrency(costPrice, ess)); cost = _("kitCost", Util.displayCurrency(costPrice, ess));
} }
@ -134,7 +135,7 @@ public class Kit
{ {
if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) if (kitItem.startsWith(ess.getSettings().getCurrencySymbol()))
{ {
Double value = Double.parseDouble(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim()); BigDecimal value = new BigDecimal(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
Trade t = new Trade(value, ess); Trade t = new Trade(value, ess);
t.pay(user); t.pay(user);
continue; continue;

View file

@ -7,6 +7,7 @@ import com.earth2me.essentials.signs.Signs;
import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.SimpleTextInput;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@ -177,12 +178,12 @@ public class Settings implements ISettings
private ConfigurationSection commandCosts; private ConfigurationSection commandCosts;
@Override @Override
public double getCommandCost(IEssentialsCommand cmd) public BigDecimal getCommandCost(IEssentialsCommand cmd)
{ {
return getCommandCost(cmd.getName()); return getCommandCost(cmd.getName());
} }
public ConfigurationSection _getCommandCosts() private ConfigurationSection _getCommandCosts()
{ {
if (config.isConfigurationSection("command-costs")) if (config.isConfigurationSection("command-costs"))
{ {
@ -228,18 +229,18 @@ public class Settings implements ISettings
} }
@Override @Override
public double getCommandCost(String name) public BigDecimal getCommandCost(String name)
{ {
name = name.replace('.', '_').replace('/', '_'); name = name.replace('.', '_').replace('/', '_');
if (commandCosts != null) if (commandCosts != null)
{ {
return commandCosts.getDouble(name, 0.0); return BigDecimal.valueOf(commandCosts.getDouble(name, 0.0));
} }
return 0.0; return BigDecimal.ZERO;
} }
private Set<String> socialSpyCommands = new HashSet<String>(); private Set<String> socialSpyCommands = new HashSet<String>();
public Set<String> _getSocialSpyCommands() private Set<String> _getSocialSpyCommands()
{ {
Set<String> socialspyCommands = new HashSet<String>(); Set<String> socialspyCommands = new HashSet<String>();
@ -289,7 +290,7 @@ public class Settings implements ISettings
} }
private ConfigurationSection kits; private ConfigurationSection kits;
public ConfigurationSection _getKits() private ConfigurationSection _getKits()
{ {
if (config.isConfigurationSection("kits")) if (config.isConfigurationSection("kits"))
{ {
@ -507,6 +508,8 @@ public class Settings implements ISettings
socialSpyCommands = _getSocialSpyCommands(); socialSpyCommands = _getSocialSpyCommands();
warnOnBuildDisallow = _warnOnBuildDisallow(); warnOnBuildDisallow = _warnOnBuildDisallow();
mailsPerMinute = _getMailsPerMinute(); mailsPerMinute = _getMailsPerMinute();
maxMoney = _getMaxMoney();
minMoney = _getMinMoney();
} }
private List<Integer> itemSpawnBl = new ArrayList<Integer>(); private List<Integer> itemSpawnBl = new ArrayList<Integer>();
@ -688,21 +691,27 @@ public class Settings implements ISettings
return config.getBoolean(configName, def); return config.getBoolean(configName, def);
} }
private final static double MAXMONEY = 10000000000000.0; private final static double MAXMONEY = 10000000000000.0;
private BigDecimal maxMoney = BigDecimal.valueOf(MAXMONEY);
@Override private BigDecimal _getMaxMoney()
public double getMaxMoney()
{ {
double max = config.getDouble("max-money", MAXMONEY); double max = config.getDouble("max-money", MAXMONEY);
if (Math.abs(max) > MAXMONEY) if (Math.abs(max) > MAXMONEY)
{ {
max = max < 0 ? -MAXMONEY : MAXMONEY; max = max < 0 ? -MAXMONEY : MAXMONEY;
} }
return max; return BigDecimal.valueOf(max);
} }
private final static double MINMONEY = -10000000000000.0;
@Override @Override
public double getMinMoney() public BigDecimal getMaxMoney()
{
return maxMoney;
}
private final static double MINMONEY = -10000000000000.0;
private BigDecimal minMoney = BigDecimal.valueOf(MINMONEY);
private BigDecimal _getMinMoney()
{ {
double min = config.getDouble("min-money", MINMONEY); double min = config.getDouble("min-money", MINMONEY);
if (min > 0) if (min > 0)
@ -713,7 +722,13 @@ public class Settings implements ISettings
{ {
min = MINMONEY; min = MINMONEY;
} }
return min; return BigDecimal.valueOf(min);
}
@Override
public BigDecimal getMinMoney()
{
return minMoney;
} }
@Override @Override
@ -974,7 +989,7 @@ public class Settings implements ISettings
} }
private long teleportInvulnerabilityTime; private long teleportInvulnerabilityTime;
public long _getTeleportInvulnerability() private long _getTeleportInvulnerability()
{ {
return config.getLong("teleport-invulnerability", 0) * 1000; return config.getLong("teleport-invulnerability", 0) * 1000;
} }

View file

@ -6,6 +6,7 @@ import com.earth2me.essentials.craftbukkit.SetExpFix;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@ -21,7 +22,7 @@ public class Trade
{ {
private final transient String command; private final transient String command;
private final transient Trade fallbackTrade; private final transient Trade fallbackTrade;
private final transient Double money; private final transient BigDecimal money;
private final transient ItemStack itemStack; private final transient ItemStack itemStack;
private final transient Integer exp; private final transient Integer exp;
private final transient IEssentials ess; private final transient IEssentials ess;
@ -43,11 +44,16 @@ public class Trade
this(command, fallback, null, null, null, ess); this(command, fallback, null, null, null, ess);
} }
public Trade(final double money, final IEssentials ess) public Trade(final BigDecimal money, final IEssentials ess)
{ {
this(null, null, money, null, null, ess); this(null, null, money, null, null, ess);
} }
public Trade(final double money, final IEssentials ess)
{
this(null, null, BigDecimal.valueOf(money), null, null, ess);
}
public Trade(final ItemStack items, final IEssentials ess) public Trade(final ItemStack items, final IEssentials ess)
{ {
this(null, null, null, items, null, ess); this(null, null, null, items, null, ess);
@ -58,7 +64,7 @@ public class Trade
this(null, null, null, null, exp, ess); this(null, null, null, null, exp, ess);
} }
private Trade(final String command, final Trade fallback, final Double money, final ItemStack item, final Integer exp, final IEssentials ess) private Trade(final String command, final Trade fallback, final BigDecimal money, final ItemStack item, final Integer exp, final IEssentials ess)
{ {
this.command = command; this.command = command;
this.fallbackTrade = fallback; this.fallbackTrade = fallback;
@ -77,7 +83,7 @@ public class Trade
} }
if (getMoney() != null if (getMoney() != null
&& getMoney() > 0 && getMoney().compareTo(BigDecimal.ZERO) > 0
&& !user.canAfford(getMoney())) && !user.canAfford(getMoney()))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
@ -89,9 +95,9 @@ public class Trade
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
} }
double money; BigDecimal money;
if (command != null && !command.isEmpty() if (command != null && !command.isEmpty()
&& 0 < (money = getCommandCost(user)) && (money = getCommandCost(user)).compareTo(BigDecimal.ZERO) > 0
&& !user.canAfford(money)) && !user.canAfford(money))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
@ -112,7 +118,7 @@ public class Trade
public boolean pay(final IUser user, final boolean dropItems) public boolean pay(final IUser user, final boolean dropItems)
{ {
boolean success = true; boolean success = true;
if (getMoney() != null && getMoney() > 0) if (getMoney() != null && getMoney().compareTo(BigDecimal.ZERO) > 0)
{ {
user.giveMoney(getMoney()); user.giveMoney(getMoney());
} }
@ -164,7 +170,7 @@ public class Trade
if (getMoney() != null) if (getMoney() != null)
{ {
if (!user.canAfford(getMoney()) && getMoney() > 0.0d) if (!user.canAfford(getMoney()) && getMoney().compareTo(BigDecimal.ZERO) > 0)
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }
@ -181,8 +187,8 @@ public class Trade
} }
if (command != null) if (command != null)
{ {
final double cost = getCommandCost(user); final BigDecimal cost = getCommandCost(user);
if (!user.canAfford(cost) && cost > 0.0d) if (!user.canAfford(cost) && cost.compareTo(BigDecimal.ZERO) > 0)
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }
@ -199,7 +205,7 @@ public class Trade
} }
} }
public Double getMoney() public BigDecimal getMoney()
{ {
return money; return money;
} }
@ -228,13 +234,13 @@ public class Trade
return TradeType.MONEY; return TradeType.MONEY;
} }
public Double getCommandCost(final IUser user) public BigDecimal getCommandCost(final IUser user)
{ {
double cost = 0.0d; BigDecimal cost = BigDecimal.ZERO;
if (command != null && !command.isEmpty()) if (command != null && !command.isEmpty())
{ {
cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
if (cost == 0.0d && fallbackTrade != null) if (cost.compareTo(BigDecimal.ZERO) == 0 && fallbackTrade != null)
{ {
cost = fallbackTrade.getCommandCost(user); cost = fallbackTrade.getCommandCost(user);
} }
@ -244,10 +250,10 @@ public class Trade
ess.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); ess.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost);
} }
} }
if (cost != 0.0d && (user.isAuthorized("essentials.nocommandcost.all") if (cost.compareTo(BigDecimal.ZERO) != 0 && (user.isAuthorized("essentials.nocommandcost.all")
|| user.isAuthorized("essentials.nocommandcost." + command))) || user.isAuthorized("essentials.nocommandcost." + command)))
{ {
return 0.0d; return BigDecimal.ZERO;
} }
return cost; return cost;
} }

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.register.payment.Method; import com.earth2me.essentials.register.payment.Method;
import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.logging.Level; import java.util.logging.Level;
@ -120,18 +121,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
@Override @Override
public void giveMoney(final double value) public void giveMoney(final BigDecimal value)
{ {
giveMoney(value, null); giveMoney(value, null);
} }
public void giveMoney(final double value, final CommandSender initiator) public void giveMoney(final BigDecimal value, final CommandSender initiator)
{ {
if (value == 0.0d) if (value.compareTo(BigDecimal.ZERO) == 0)
{ {
return; return;
} }
setMoney(getMoney() + value); setMoney(getMoney().add(value));
sendMessage(_("addedToAccount", Util.displayCurrency(value, ess))); sendMessage(_("addedToAccount", Util.displayCurrency(value, ess)));
if (initiator != null) if (initiator != null)
{ {
@ -139,16 +140,16 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
} }
public void payUser(final User reciever, final double value) throws Exception public void payUser(final User reciever, final BigDecimal value) throws Exception
{ {
if (value == 0.0d) if (value.compareTo(BigDecimal.ZERO) == 0)
{ {
return; return;
} }
if (canAfford(value)) if (canAfford(value))
{ {
setMoney(getMoney() - value); setMoney(getMoney().subtract(value));
reciever.setMoney(reciever.getMoney() + value); reciever.setMoney(reciever.getMoney().add(value));
sendMessage(_("moneySentTo", Util.displayCurrency(value, ess), reciever.getDisplayName())); sendMessage(_("moneySentTo", Util.displayCurrency(value, ess), reciever.getDisplayName()));
reciever.sendMessage(_("moneyRecievedFrom", Util.displayCurrency(value, ess), getDisplayName())); reciever.sendMessage(_("moneyRecievedFrom", Util.displayCurrency(value, ess), getDisplayName()));
} }
@ -159,18 +160,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
@Override @Override
public void takeMoney(final double value) public void takeMoney(final BigDecimal value)
{ {
takeMoney(value, null); takeMoney(value, null);
} }
public void takeMoney(final double value, final CommandSender initiator) public void takeMoney(final BigDecimal value, final CommandSender initiator)
{ {
if (value == 0.0d) if (value.compareTo(BigDecimal.ZERO) == 0)
{ {
return; return;
} }
setMoney(getMoney() - value); setMoney(getMoney().subtract(value));
sendMessage(_("takenFromAccount", Util.displayCurrency(value, ess))); sendMessage(_("takenFromAccount", Util.displayCurrency(value, ess)));
if (initiator != null) if (initiator != null)
{ {
@ -179,23 +180,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
@Override @Override
public boolean canAfford(final double cost) public boolean canAfford(final BigDecimal cost)
{ {
return canAfford(cost, true); return canAfford(cost, true);
} }
public boolean canAfford(final double cost, final boolean permcheck) public boolean canAfford(final BigDecimal cost, final boolean permcheck)
{ {
if (cost <= 0.0d) if (cost.compareTo(BigDecimal.ZERO) <= 0)
{ {
return true; return true;
} }
final double mon = getMoney(); final BigDecimal remainingBalance = getMoney().subtract(cost);
if (!permcheck || isAuthorized("essentials.eco.loan")) if (!permcheck || isAuthorized("essentials.eco.loan"))
{ {
return (mon - cost) >= ess.getSettings().getMinMoney(); return (remainingBalance.compareTo(ess.getSettings().getMinMoney()) >= 0);
} }
return cost <= mon; return (remainingBalance.compareTo(BigDecimal.ZERO) >= 0);
} }
public void dispose() public void dispose()
@ -391,7 +392,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
@Override @Override
public double getMoney() public BigDecimal getMoney()
{ {
if (ess.getPaymentMethod().hasMethod()) if (ess.getPaymentMethod().hasMethod())
{ {
@ -403,7 +404,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(); throw new Exception();
} }
final Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName()); final Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName());
return account.balance(); return BigDecimal.valueOf(account.balance());
} }
catch (Throwable ex) catch (Throwable ex)
{ {
@ -413,7 +414,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
@Override @Override
public void setMoney(final double value) public void setMoney(final BigDecimal value)
{ {
if (ess.getPaymentMethod().hasMethod()) if (ess.getPaymentMethod().hasMethod())
{ {
@ -425,7 +426,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(); throw new Exception();
} }
final Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName()); final Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName());
account.set(value); account.set(value.doubleValue());
} }
catch (Throwable ex) catch (Throwable ex)
{ {
@ -435,7 +436,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
Trade.log("Update", "Set", "API", getName(), new Trade(value, ess), null, null, null, ess); Trade.log("Update", "Set", "API", getName(), new Trade(value, ess), null, null, null, ess);
} }
public void updateMoneyCache(final double value) public void updateMoneyCache(final BigDecimal value)
{ {
if (ess.getPaymentMethod().hasMethod() && super.getMoney() != value) if (ess.getPaymentMethod().hasMethod() && super.getMoney() != value)
{ {

View file

@ -2,6 +2,7 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -66,33 +67,47 @@ public abstract class UserData extends PlayerExtension implements IConf
ignoredPlayers = _getIgnoredPlayers(); ignoredPlayers = _getIgnoredPlayers();
logoutLocation = _getLogoutLocation(); logoutLocation = _getLogoutLocation();
} }
private double money; private BigDecimal money;
private double _getMoney() private BigDecimal _getMoney()
{ {
double money = ess.getSettings().getStartingBalance(); double bal = ess.getSettings().getStartingBalance();
BigDecimal maxMoney = ess.getSettings().getMaxMoney();
BigDecimal minMoney = ess.getSettings().getMinMoney();
if (config.hasProperty("money")) if (config.hasProperty("money"))
{ {
money = config.getDouble("money", money); bal = config.getDouble("money", bal);
} }
if (Math.abs(money) > ess.getSettings().getMaxMoney()) BigDecimal result = BigDecimal.valueOf(bal);
if (result.compareTo(maxMoney) > 0)
{ {
money = money < 0 ? -ess.getSettings().getMaxMoney() : ess.getSettings().getMaxMoney(); result = maxMoney;
} }
return money; if (result.compareTo(minMoney) < 0)
{
result = minMoney;
}
return result;
} }
public double getMoney() public BigDecimal getMoney()
{ {
return money; return money;
} }
public void setMoney(double value) public void setMoney(BigDecimal value)
{ {
money = Util.sanitizeMoney(value); money = value;
if (Math.abs(money) > ess.getSettings().getMaxMoney()) BigDecimal maxMoney = ess.getSettings().getMaxMoney();
BigDecimal minMoney = ess.getSettings().getMinMoney();
if (money.compareTo(maxMoney) > 0)
{ {
money = money < 0 ? -ess.getSettings().getMaxMoney() : ess.getSettings().getMaxMoney(); money = maxMoney;
}
if (money.compareTo(minMoney) < 0)
{
money = minMoney;
} }
config.setProperty("money", money); config.setProperty("money", money);
config.save(); config.save();

View file

@ -2,7 +2,6 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
@ -524,18 +523,12 @@ public class Util
return is; 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)); private static DecimalFormat dFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
public static String formatAsCurrency(final double value) public static String formatAsCurrency(final BigDecimal value)
{ {
double fvalue = sanitizeMoney(value);
dFormat.setRoundingMode(RoundingMode.FLOOR); dFormat.setRoundingMode(RoundingMode.FLOOR);
String str = dFormat.format(fvalue); String str = dFormat.format(value);
if (str.endsWith(".00")) if (str.endsWith(".00"))
{ {
str = str.substring(0, str.length() - 3); str = str.substring(0, str.length() - 3);
@ -543,16 +536,21 @@ public class Util
return str; return str;
} }
public static String displayCurrency(final double value, final IEssentials ess) public static String displayCurrency(final BigDecimal value, final IEssentials ess)
{ {
return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value)); return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value));
} }
public static String shortCurrency(final double value, final IEssentials ess) public static String shortCurrency(final BigDecimal value, final IEssentials ess)
{ {
return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value); return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value);
} }
public static String shortCurrency(final double value, final IEssentials ess)
{
return shortCurrency(BigDecimal.valueOf(value), ess);
}
public static boolean isInt(final String sInt) public static boolean isInt(final String sInt)
{ {
try try

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -18,7 +19,7 @@ public class Worth implements IConf
config.load(); config.load();
} }
public double getPrice(ItemStack itemStack) public BigDecimal getPrice(ItemStack itemStack)
{ {
String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
double result; double result;
@ -35,7 +36,11 @@ public class Worth implements IConf
{ {
result = config.getDouble("worth-" + itemStack.getTypeId(), Double.NaN); result = config.getDouble("worth-" + itemStack.getTypeId(), Double.NaN);
} }
return result; if (Double.isNaN(result))
{
return null;
}
return BigDecimal.valueOf(result);
} }
public void setPrice(ItemStack itemStack, double price) public void setPrice(ItemStack itemStack, double price)

View file

@ -6,6 +6,7 @@ import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -87,7 +88,7 @@ public final class Economy
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
} }
return user.getMoney(); return user.getMoney().doubleValue();
} }
/** /**
@ -100,19 +101,20 @@ public final class Economy
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
{ {
User user = getUserByName(name); User user = getUserByName(name);
BigDecimal newBalance = BigDecimal.valueOf(balance);
if (user == null) if (user == null)
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
} }
if (balance < ess.getSettings().getMinMoney()) if (newBalance.compareTo(ess.getSettings().getMinMoney()) < 0)
{ {
throw new NoLoanPermittedException(); throw new NoLoanPermittedException();
} }
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan")) if (newBalance.compareTo(BigDecimal.ZERO) < 0 && !user.isAuthorized("essentials.eco.loan"))
{ {
throw new NoLoanPermittedException(); throw new NoLoanPermittedException();
} }
user.setMoney(balance); user.setMoney(newBalance);
} }
/** /**
@ -238,7 +240,7 @@ public final class Economy
{ {
throw new RuntimeException(noCallBeforeLoad); throw new RuntimeException(noCallBeforeLoad);
} }
return Util.displayCurrency(amount, ess); return Util.displayCurrency(BigDecimal.valueOf(amount), ess);
} }
/** /**

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.math.BigDecimal;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -32,13 +33,13 @@ public class Commandbalance extends EssentialsCommand
if (args.length < 1 || !user.isAuthorized("essentials.balance.others")) if (args.length < 1 || !user.isAuthorized("essentials.balance.others"))
{ {
final double bal = user.getMoney(); final BigDecimal bal = user.getMoney();
user.sendMessage(_("balance", Util.displayCurrency(bal, ess))); user.sendMessage(_("balance", Util.displayCurrency(bal, ess)));
} }
else else
{ {
final User target = getPlayer(server, args, 0, true, true); final User target = getPlayer(server, args, 0, true, true);
final double bal = target.getMoney(); final BigDecimal bal = target.getMoney();
user.sendMessage(_("balanceOther", target.getDisplayName(), Util.displayCurrency(bal, ess))); user.sendMessage(_("balanceOther", target.getDisplayName(), Util.displayCurrency(bal, ess)));
} }
} }

View file

@ -5,6 +5,7 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.textreader.TextPager;
import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -106,33 +107,33 @@ public class Commandbalancetop extends EssentialsCommand
if (force || cacheage <= System.currentTimeMillis() - CACHETIME) if (force || cacheage <= System.currentTimeMillis() - CACHETIME)
{ {
cache.getLines().clear(); cache.getLines().clear();
final Map<String, Double> balances = new HashMap<String, Double>(); final Map<String, BigDecimal> balances = new HashMap<String, BigDecimal>();
double totalMoney = 0d; BigDecimal totalMoney = BigDecimal.ZERO;
for (String u : ess.getUserMap().getAllUniqueUsers()) for (String u : ess.getUserMap().getAllUniqueUsers())
{ {
final User user = ess.getUserMap().getUser(u); final User user = ess.getUserMap().getUser(u);
if (user != null) if (user != null)
{ {
final double userMoney = user.getMoney(); final BigDecimal userMoney = user.getMoney();
user.updateMoneyCache(userMoney); user.updateMoneyCache(userMoney);
totalMoney += userMoney; totalMoney = totalMoney.add(userMoney);
balances.put(user.getDisplayName(), userMoney); balances.put(user.getDisplayName(), userMoney);
} }
} }
final List<Map.Entry<String, Double>> sortedEntries = new ArrayList<Map.Entry<String, Double>>(balances.entrySet()); final List<Map.Entry<String, BigDecimal>> sortedEntries = new ArrayList<Map.Entry<String, BigDecimal>>(balances.entrySet());
Collections.sort(sortedEntries, new Comparator<Map.Entry<String, Double>>() Collections.sort(sortedEntries, new Comparator<Map.Entry<String, BigDecimal>>()
{ {
@Override @Override
public int compare(final Entry<String, Double> entry1, final Entry<String, Double> entry2) public int compare(final Entry<String, BigDecimal> entry1, final Entry<String, BigDecimal> entry2)
{ {
return -entry1.getValue().compareTo(entry2.getValue()); return entry2.getValue().compareTo(entry1.getValue());
} }
}); });
cache.getLines().add(_("serverTotal", Util.displayCurrency(totalMoney, ess))); cache.getLines().add(_("serverTotal", Util.displayCurrency(totalMoney, ess)));
int pos = 1; int pos = 1;
for (Map.Entry<String, Double> entry : sortedEntries) for (Map.Entry<String, BigDecimal> entry : sortedEntries)
{ {
cache.getLines().add(pos + ". " + entry.getKey() + ", " + Util.displayCurrency(entry.getValue(), ess)); cache.getLines().add(pos + ". " + entry.getKey() + ", " + Util.displayCurrency(entry.getValue(), ess));
pos++; pos++;

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -25,14 +26,14 @@ public class Commandeco extends EssentialsCommand
} }
Commandeco.EcoCommands cmd; Commandeco.EcoCommands cmd;
double startingBalance = (double)ess.getSettings().getStartingBalance(); BigDecimal startingBalance = new BigDecimal(ess.getSettings().getStartingBalance());
double amount; BigDecimal amount;
Double broadcast = null; BigDecimal broadcast = null;
Double broadcastAll = null; BigDecimal broadcastAll = null;
try try
{ {
cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH)); cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")); amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : new BigDecimal(args[2].replaceAll("[^0-9\\.]", ""));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -107,26 +108,26 @@ public class Commandeco extends EssentialsCommand
if (broadcast != null) if (broadcast != null)
{ {
server.broadcastMessage(_("resetBal", Util.formatAsCurrency(broadcast))); server.broadcastMessage(_("resetBal", Util.displayCurrency(broadcast, ess)));
} }
if (broadcastAll != null) if (broadcastAll != null)
{ {
server.broadcastMessage(_("resetBalAll", Util.formatAsCurrency(broadcastAll))); server.broadcastMessage(_("resetBalAll", Util.displayCurrency(broadcastAll, ess)));
} }
} }
private void take(double amount, final User player, final CommandSender sender) throws Exception private void take(BigDecimal amount, final User player, final CommandSender sender) throws Exception
{ {
double money = player.getMoney(); BigDecimal money = player.getMoney();
double minBalance = ess.getSettings().getMinMoney(); BigDecimal minBalance = ess.getSettings().getMinMoney();
if (money - amount > minBalance) if (money.subtract(amount).compareTo(minBalance) > 0)
{ {
player.takeMoney(amount, sender); player.takeMoney(amount, sender);
} }
else if (sender == null) else if (sender == null)
{ {
player.setMoney(minBalance); player.setMoney(minBalance);
player.sendMessage(_("takenFromAccount", Util.displayCurrency(money - minBalance, ess))); player.sendMessage(_("takenFromAccount", Util.displayCurrency(player.getMoney(), ess)));
} }
else else
{ {
@ -134,10 +135,10 @@ public class Commandeco extends EssentialsCommand
} }
} }
private void set(double amount, final User player, final CommandSender sender) private void set(BigDecimal amount, final User player, final CommandSender sender)
{ {
double minBalance = ess.getSettings().getMinMoney(); BigDecimal minBalance = ess.getSettings().getMinMoney();
boolean underMinimum = amount < minBalance; boolean underMinimum = (amount.compareTo(minBalance) < 0);
player.setMoney(underMinimum ? minBalance : amount); player.setMoney(underMinimum ? minBalance : amount);
player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess))); player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess)));
if (sender != null) if (sender != null)

View file

@ -250,7 +250,7 @@ public class Commandessentials extends EssentialsCommand
long timeDiff = System.currentTimeMillis() - lastLog; long timeDiff = System.currentTimeMillis() - lastLog;
long milliDays = daysArg * 24L * 60L * 60L * 1000L; long milliDays = daysArg * 24L * 60L * 60L * 1000L;
int homeCount = user.getHomes().size(); int homeCount = user.getHomes().size();
double moneyCount = user.getMoney(); double moneyCount = user.getMoney().doubleValue();
if ((lastLog == 0) || (ban > bansArg) || (timeDiff < milliDays) if ((lastLog == 0) || (ban > bansArg) || (timeDiff < milliDays)
|| (homeCount > homesArg) || (moneyCount > moneyArg)) || (homeCount > homesArg) || (moneyCount > moneyArg))

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -29,7 +30,7 @@ public class Commandpay extends EssentialsCommand
throw new NotEnoughArgumentsException("You need to specify a player to pay."); throw new NotEnoughArgumentsException("You need to specify a player to pay.");
} }
double amount = Double.parseDouble(args[1].replaceAll("[^0-9\\.]", "")); BigDecimal amount = new BigDecimal(args[1].replaceAll("[^0-9\\.]", ""));
boolean skipHidden = !user.isAuthorized("essentials.vanish.interact"); boolean skipHidden = !user.isAuthorized("essentials.vanish.interact");
boolean foundUser = false; boolean foundUser = false;

View file

@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Material; import org.bukkit.Material;
@ -21,7 +22,7 @@ public class Commandsell extends EssentialsCommand
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
double totalWorth = 0.0; BigDecimal totalWorth = BigDecimal.ZERO;
String type = ""; String type = "";
if (args.length < 1) if (args.length < 1)
{ {
@ -42,13 +43,13 @@ public class Commandsell extends EssentialsCommand
} }
try try
{ {
totalWorth += sellItem(user, stack, args, true); totalWorth = totalWorth.add(sellItem(user, stack, args, true));
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
if (totalWorth > 0) if (totalWorth.compareTo(BigDecimal.ZERO) > 0)
{ {
user.sendMessage(_("totalWorthAll", type, Util.displayCurrency(totalWorth, ess))); user.sendMessage(_("totalWorthAll", type, Util.displayCurrency(totalWorth, ess)));
} }
@ -64,13 +65,13 @@ public class Commandsell extends EssentialsCommand
} }
try try
{ {
totalWorth += sellItem(user, stack, args, true); totalWorth = totalWorth.add(sellItem(user, stack, args, true));
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
if (totalWorth > 0) if (totalWorth.compareTo(BigDecimal.ZERO) > 0)
{ {
user.sendMessage(_("totalWorthBlocks", type, Util.displayCurrency(totalWorth, ess))); user.sendMessage(_("totalWorthBlocks", type, Util.displayCurrency(totalWorth, ess)));
} }
@ -83,7 +84,7 @@ public class Commandsell extends EssentialsCommand
sellItem(user, is, args, false); sellItem(user, is, args, false);
} }
private double sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception
{ {
if (is == null || is.getType() == Material.AIR) if (is == null || is.getType() == Material.AIR)
{ {
@ -99,11 +100,11 @@ public class Commandsell extends EssentialsCommand
amount = -amount; amount = -amount;
} }
} }
double worth = ess.getWorth().getPrice(is); BigDecimal worth = ess.getWorth().getPrice(is);
boolean stack = args.length > 1 && args[1].endsWith("s"); boolean stack = args.length > 1 && args[1].endsWith("s");
boolean requireStack = ess.getSettings().isTradeInStacks(id); boolean requireStack = ess.getSettings().isTradeInStacks(id);
if (Double.isNaN(worth)) if (worth == null)
{ {
throw new Exception(_("itemCannotBeSold")); throw new Exception(_("itemCannotBeSold"));
} }
@ -146,10 +147,11 @@ public class Commandsell extends EssentialsCommand
} }
else else
{ {
return worth * amount; return worth.multiply(new BigDecimal(amount));
} }
} }
BigDecimal result = worth.multiply(new BigDecimal(amount));
//TODO: Prices for Enchantments //TODO: Prices for Enchantments
final ItemStack ris = is.clone(); final ItemStack ris = is.clone();
ris.setAmount(amount); ris.setAmount(amount);
@ -159,10 +161,10 @@ public class Commandsell extends EssentialsCommand
} }
user.getInventory().removeItem(ris); user.getInventory().removeItem(ris);
user.updateInventory(); user.updateInventory();
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), user.getLocation(), ess); Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), ess);
user.giveMoney(worth * amount); user.giveMoney(result);
user.sendMessage(_("itemSold", Util.displayCurrency(worth * amount, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth, ess))); user.sendMessage(_("itemSold", Util.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth, ess)));
logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth * amount, ess), amount, Util.displayCurrency(worth, ess))); logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(result, ess), amount, Util.displayCurrency(worth, ess)));
return worth * amount; return result;
} }
} }

View file

@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.Warps; import com.earth2me.essentials.Warps;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -110,7 +111,7 @@ public class Commandwarp extends EssentialsCommand
{ {
final Trade chargeWarp = new Trade("warp-" + name.toLowerCase(Locale.ENGLISH).replace('_', '-'), ess); final Trade chargeWarp = new Trade("warp-" + name.toLowerCase(Locale.ENGLISH).replace('_', '-'), ess);
final Trade chargeCmd = new Trade(this.getName(), ess); final Trade chargeCmd = new Trade(this.getName(), ess);
final double fullCharge = chargeWarp.getCommandCost(user) + chargeCmd.getCommandCost(user); final BigDecimal fullCharge = chargeWarp.getCommandCost(user).add(chargeCmd.getCommandCost(user));
final Trade charge = new Trade(fullCharge, ess); final Trade charge = new Trade(fullCharge, ess);
charge.isAffordableFor(owner); charge.isAffordableFor(owner);
if (ess.getSettings().getPerWarpPermission() && !owner.isAuthorized("essentials.warps." + name)) if (ess.getSettings().getPerWarpPermission() && !owner.isAuthorized("essentials.warps." + name))

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -41,22 +42,24 @@ public class Commandworth extends EssentialsCommand
} }
iStack.setAmount(amount); iStack.setAmount(amount);
final double worth = ess.getWorth().getPrice(iStack); final BigDecimal worth = ess.getWorth().getPrice(iStack);
if (Double.isNaN(worth)) if (worth == null)
{ {
throw new Exception(_("itemCannotBeSold")); throw new Exception(_("itemCannotBeSold"));
} }
final BigDecimal result = worth.multiply(new BigDecimal(amount));
user.sendMessage(iStack.getDurability() != 0 user.sendMessage(iStack.getDurability() != 0
? _("worthMeta", ? _("worthMeta",
iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
iStack.getDurability(), iStack.getDurability(),
Util.displayCurrency(worth * amount, ess), Util.displayCurrency(result, ess),
amount, amount,
Util.displayCurrency(worth, ess)) Util.displayCurrency(worth, ess))
: _("worth", : _("worth",
iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
Util.displayCurrency(worth * amount, ess), Util.displayCurrency(result, ess),
amount, amount,
Util.displayCurrency(worth, ess))); Util.displayCurrency(worth, ess)));
} }
@ -85,24 +88,25 @@ public class Commandworth extends EssentialsCommand
} }
iStack.setAmount(amount); iStack.setAmount(amount);
final double worth = ess.getWorth().getPrice(iStack); final BigDecimal worth = ess.getWorth().getPrice(iStack);
if (Double.isNaN(worth)) if (worth == null)
{ {
throw new Exception(_("itemCannotBeSold")); throw new Exception(_("itemCannotBeSold"));
} }
final BigDecimal result = worth.multiply(new BigDecimal(amount));
sender.sendMessage(iStack.getDurability() != 0 sender.sendMessage(iStack.getDurability() != 0
? _("worthMeta", ? _("worthMeta",
iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
iStack.getDurability(), iStack.getDurability(),
Util.displayCurrency(worth * amount, ess), Util.displayCurrency(result, ess),
amount, amount,
Util.displayCurrency(worth, ess)) Util.displayCurrency(worth, ess))
: _("worth", : _("worth",
iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
Util.displayCurrency(worth * amount, ess), Util.displayCurrency(result, ess),
amount, amount,
Util.displayCurrency(worth, ess))); Util.displayCurrency(worth, ess)));
} }
} }

View file

@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.*; import com.earth2me.essentials.*;
import java.math.BigDecimal;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -277,7 +278,7 @@ public class EssentialsSign
return; return;
} }
final Trade trade = getTrade(sign, index, 0, ess); final Trade trade = getTrade(sign, index, 0, ess);
final Double money = trade.getMoney(); final BigDecimal money = trade.getMoney();
if (money != null) if (money != null)
{ {
sign.setLine(index, Util.shortCurrency(money, ess)); sign.setLine(index, Util.shortCurrency(money, ess));

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.signs;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade.TradeType; import com.earth2me.essentials.Trade.TradeType;
import com.earth2me.essentials.*; import com.earth2me.essentials.*;
import java.math.BigDecimal;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
//TODO: TL exceptions //TODO: TL exceptions
@ -265,10 +266,10 @@ public class SignTrade extends EssentialsSign
protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
{ {
final Double money = trade.getMoney(); final BigDecimal money = trade.getMoney();
if (money != null) if (money != null)
{ {
changeAmount(sign, index, -money, ess); changeAmount(sign, index, -money.doubleValue(), ess);
} }
final ItemStack item = trade.getItemStack(); final ItemStack item = trade.getItemStack();
if (item != null) if (item != null)
@ -284,10 +285,10 @@ public class SignTrade extends EssentialsSign
protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
{ {
final Double money = trade.getMoney(); final BigDecimal money = trade.getMoney();
if (money != null) if (money != null)
{ {
changeAmount(sign, index, money, ess); changeAmount(sign, index, money.doubleValue(), ess);
} }
final ItemStack item = trade.getItemStack(); final ItemStack item = trade.getItemStack();
if (item != null) if (item != null)

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
@ -69,13 +70,13 @@ public class UserTest extends TestCase
{ {
should("properly set, take, give, and get money"); should("properly set, take, give, and get money");
User user = ess.getUser(base1); User user = ess.getUser(base1);
double i; double i = 100.5;
user.setMoney(i = 100.5); user.setMoney(BigDecimal.valueOf(i));
user.takeMoney(50); user.takeMoney(new BigDecimal(50));
i -= 50; i -= 50;
user.giveMoney(25); user.giveMoney(new BigDecimal(25));
i += 25; i += 25;
assertEquals(user.getMoney(), i); assertEquals(user.getMoney().doubleValue(), i);
} }
public void testGetGroup() public void testGetGroup()