mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-19 09:06:09 +01:00
ECONOMY MADNESS? THIS IS … FIXED
This commit is contained in:
parent
aaebb6143e
commit
6044cca54f
@ -5,6 +5,9 @@ import static com.earth2me.essentials.I18n._;
|
|||||||
import com.earth2me.essentials.api.InvalidWorldException;
|
import com.earth2me.essentials.api.InvalidWorldException;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.math.MathContext;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -493,6 +496,11 @@ public class EssentialsConf extends YamlConfiguration
|
|||||||
{
|
{
|
||||||
return get(path);
|
return get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProperty(final String path, final BigDecimal bigDecimal)
|
||||||
|
{
|
||||||
|
set(path, bigDecimal.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void setProperty(String path, Object object)
|
public void setProperty(String path, Object object)
|
||||||
{
|
{
|
||||||
@ -515,6 +523,32 @@ public class EssentialsConf extends YamlConfiguration
|
|||||||
{
|
{
|
||||||
return super.get(path, def);
|
return super.get(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized BigDecimal getBigDecimal(final String path, final BigDecimal def)
|
||||||
|
{
|
||||||
|
final String input = super.getString(path);
|
||||||
|
return toBigDecimal(input, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BigDecimal toBigDecimal(final String input, final BigDecimal def)
|
||||||
|
{
|
||||||
|
if (input == null || input.isEmpty())
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new BigDecimal(input, MathContext.DECIMAL128);
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean getBoolean(String path)
|
public synchronized boolean getBoolean(String path)
|
||||||
|
@ -79,7 +79,7 @@ public interface ISettings extends IConf
|
|||||||
|
|
||||||
int getSpawnMobLimit();
|
int getSpawnMobLimit();
|
||||||
|
|
||||||
int getStartingBalance();
|
BigDecimal getStartingBalance();
|
||||||
|
|
||||||
double getTeleportCooldown();
|
double getTeleportCooldown();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public class Kit
|
|||||||
{
|
{
|
||||||
String cost = "";
|
String cost = "";
|
||||||
BigDecimal 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.compareTo(BigDecimal.ZERO) > 0)
|
if (costPrice.signum() > 0)
|
||||||
{
|
{
|
||||||
cost = _("kitCost", Util.displayCurrency(costPrice, ess));
|
cost = _("kitCost", Util.displayCurrency(costPrice, ess));
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,9 @@ public class Settings implements ISettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getStartingBalance()
|
public BigDecimal getStartingBalance()
|
||||||
{
|
{
|
||||||
return config.getInt("starting-balance", 0);
|
return config.getBigDecimal("starting-balance", BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -234,7 +234,7 @@ public class Settings implements ISettings
|
|||||||
name = name.replace('.', '_').replace('/', '_');
|
name = name.replace('.', '_').replace('/', '_');
|
||||||
if (commandCosts != null)
|
if (commandCosts != null)
|
||||||
{
|
{
|
||||||
return BigDecimal.valueOf(commandCosts.getDouble(name, 0.0));
|
return EssentialsConf.toBigDecimal(commandCosts.getString(name), BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
@ -690,42 +690,33 @@ 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 BigDecimal MAXMONEY = new BigDecimal("10000000000000");
|
||||||
private BigDecimal maxMoney = BigDecimal.valueOf(MAXMONEY);
|
private BigDecimal maxMoney = MAXMONEY;
|
||||||
|
|
||||||
private BigDecimal _getMaxMoney()
|
private BigDecimal _getMaxMoney()
|
||||||
{
|
{
|
||||||
double max = config.getDouble("max-money", MAXMONEY);
|
return config.getBigDecimal("max-money", MAXMONEY);
|
||||||
if (Math.abs(max) > MAXMONEY)
|
|
||||||
{
|
|
||||||
max = max < 0 ? -MAXMONEY : MAXMONEY;
|
|
||||||
}
|
|
||||||
return BigDecimal.valueOf(max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal getMaxMoney()
|
public BigDecimal getMaxMoney()
|
||||||
{
|
{
|
||||||
return maxMoney;
|
return maxMoney;
|
||||||
}
|
}
|
||||||
private final static double MINMONEY = -10000000000000.0;
|
private final static BigDecimal MINMONEY = new BigDecimal("-10000000000000");
|
||||||
private BigDecimal minMoney = BigDecimal.valueOf(MINMONEY);
|
private BigDecimal minMoney = MINMONEY;
|
||||||
|
|
||||||
private BigDecimal _getMinMoney()
|
private BigDecimal _getMinMoney()
|
||||||
{
|
{
|
||||||
double min = config.getDouble("min-money", MINMONEY);
|
BigDecimal min = config.getBigDecimal("min-money", MINMONEY);
|
||||||
if (min > 0)
|
if (min.signum() > 0)
|
||||||
{
|
{
|
||||||
min = -min;
|
min = min.negate();
|
||||||
}
|
}
|
||||||
if (min < MINMONEY)
|
return min;
|
||||||
{
|
|
||||||
min = MINMONEY;
|
|
||||||
}
|
|
||||||
return BigDecimal.valueOf(min);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal getMinMoney()
|
public BigDecimal getMinMoney()
|
||||||
{
|
{
|
||||||
return minMoney;
|
return minMoney;
|
||||||
|
@ -79,7 +79,7 @@ public class Trade
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getMoney() != null
|
if (getMoney() != null
|
||||||
&& getMoney().compareTo(BigDecimal.ZERO) > 0
|
&& getMoney().signum() > 0
|
||||||
&& !user.canAfford(getMoney()))
|
&& !user.canAfford(getMoney()))
|
||||||
{
|
{
|
||||||
throw new ChargeException(_("notEnoughMoney"));
|
throw new ChargeException(_("notEnoughMoney"));
|
||||||
@ -93,7 +93,7 @@ public class Trade
|
|||||||
|
|
||||||
BigDecimal money;
|
BigDecimal money;
|
||||||
if (command != null && !command.isEmpty()
|
if (command != null && !command.isEmpty()
|
||||||
&& (money = getCommandCost(user)).compareTo(BigDecimal.ZERO) > 0
|
&& (money = getCommandCost(user)).signum() > 0
|
||||||
&& !user.canAfford(money))
|
&& !user.canAfford(money))
|
||||||
{
|
{
|
||||||
throw new ChargeException(_("notEnoughMoney"));
|
throw new ChargeException(_("notEnoughMoney"));
|
||||||
@ -114,7 +114,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().compareTo(BigDecimal.ZERO) > 0)
|
if (getMoney() != null && getMoney().signum() > 0)
|
||||||
{
|
{
|
||||||
user.giveMoney(getMoney());
|
user.giveMoney(getMoney());
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public class Trade
|
|||||||
|
|
||||||
if (getMoney() != null)
|
if (getMoney() != null)
|
||||||
{
|
{
|
||||||
if (!user.canAfford(getMoney()) && getMoney().compareTo(BigDecimal.ZERO) > 0)
|
if (!user.canAfford(getMoney()) && getMoney().signum() > 0)
|
||||||
{
|
{
|
||||||
throw new ChargeException(_("notEnoughMoney"));
|
throw new ChargeException(_("notEnoughMoney"));
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
|
|
||||||
public boolean canAfford(final BigDecimal cost, final boolean permcheck)
|
public boolean canAfford(final BigDecimal cost, final boolean permcheck)
|
||||||
{
|
{
|
||||||
if (cost.compareTo(BigDecimal.ZERO) <= 0)
|
if (cost.signum() <= 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
return (remainingBalance.compareTo(ess.getSettings().getMinMoney()) >= 0);
|
return (remainingBalance.compareTo(ess.getSettings().getMinMoney()) >= 0);
|
||||||
}
|
}
|
||||||
return (remainingBalance.compareTo(BigDecimal.ZERO) >= 0);
|
return (remainingBalance.signum() >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose()
|
public void dispose()
|
||||||
|
@ -71,15 +71,14 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
|
|
||||||
private BigDecimal _getMoney()
|
private BigDecimal _getMoney()
|
||||||
{
|
{
|
||||||
double bal = ess.getSettings().getStartingBalance();
|
BigDecimal result = ess.getSettings().getStartingBalance();
|
||||||
BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
||||||
BigDecimal minMoney = ess.getSettings().getMinMoney();
|
BigDecimal minMoney = ess.getSettings().getMinMoney();
|
||||||
|
|
||||||
if (config.hasProperty("money"))
|
if (config.hasProperty("money"))
|
||||||
{
|
{
|
||||||
bal = config.getDouble("money", bal);
|
result = config.getBigDecimal("money", result);
|
||||||
}
|
}
|
||||||
BigDecimal result = BigDecimal.valueOf(bal);
|
|
||||||
if (result.compareTo(maxMoney) > 0)
|
if (result.compareTo(maxMoney) > 0)
|
||||||
{
|
{
|
||||||
result = maxMoney;
|
result = maxMoney;
|
||||||
|
@ -22,25 +22,25 @@ public class Worth implements IConf
|
|||||||
public BigDecimal 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;
|
BigDecimal result;
|
||||||
result = config.getDouble("worth." + itemname + "." + itemStack.getDurability(), Double.NaN);
|
result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
|
||||||
if (Double.isNaN(result))
|
if (result.signum() <= 0)
|
||||||
{
|
{
|
||||||
result = config.getDouble("worth." + itemname + ".0", Double.NaN);
|
result = config.getBigDecimal("worth." + itemname + ".0", BigDecimal.ONE.negate());
|
||||||
}
|
}
|
||||||
if (Double.isNaN(result))
|
if (result.signum() <= 0)
|
||||||
{
|
{
|
||||||
result = config.getDouble("worth." + itemname, Double.NaN);
|
result = config.getBigDecimal("worth." + itemname, BigDecimal.ONE.negate());
|
||||||
}
|
}
|
||||||
if (Double.isNaN(result))
|
if (result.signum() <= 0)
|
||||||
{
|
{
|
||||||
result = config.getDouble("worth-" + itemStack.getTypeId(), Double.NaN);
|
result = config.getBigDecimal("worth-" + itemStack.getTypeId(), BigDecimal.ONE.negate());
|
||||||
}
|
}
|
||||||
if (Double.isNaN(result))
|
if (result.signum() <= 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return BigDecimal.valueOf(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrice(ItemStack itemStack, double price)
|
public void setPrice(ItemStack itemStack, double price)
|
||||||
|
@ -7,13 +7,13 @@ 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.math.BigDecimal;
|
||||||
|
import java.math.MathContext;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instead of using this api directly, we recommend to use the register plugin:
|
* Instead of using this api directly, we recommend to use the register plugin: http://bit.ly/RegisterMethod
|
||||||
* http://bit.ly/RegisterMethod
|
|
||||||
*/
|
*/
|
||||||
public final class Economy
|
public final class Economy
|
||||||
{
|
{
|
||||||
@ -23,6 +23,7 @@ public final class Economy
|
|||||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
private static IEssentials ess;
|
private static IEssentials ess;
|
||||||
private static final String noCallBeforeLoad = "Essentials API is called before Essentials is loaded.";
|
private static final String noCallBeforeLoad = "Essentials API is called before Essentials is loaded.";
|
||||||
|
public static final MathContext MATH_CONTEXT = MathContext.DECIMAL128;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param aEss the ess to set
|
* @param aEss the ess to set
|
||||||
@ -77,100 +78,177 @@ public final class Economy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the balance of a user
|
* Returns the balance of a user
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @return balance
|
* @return balance
|
||||||
* @throws UserDoesNotExistException
|
* @throws UserDoesNotExistException
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static double getMoney(String name) throws UserDoesNotExistException
|
public static double getMoney(String name) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
return getMoneyExact(name).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BigDecimal getMoneyExact(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
User user = getUserByName(name);
|
User user = getUserByName(name);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new UserDoesNotExistException(name);
|
||||||
}
|
}
|
||||||
return user.getMoney().doubleValue();
|
return user.getMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the balance of a user
|
* Sets the balance of a user
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @param balance The balance you want to set
|
* @param balance The balance you want to set
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
setMoney(name, BigDecimal.valueOf(balance));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMoney(String name, BigDecimal 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 (newBalance.compareTo(ess.getSettings().getMinMoney()) < 0)
|
if (balance.compareTo(ess.getSettings().getMinMoney()) < 0)
|
||||||
{
|
{
|
||||||
throw new NoLoanPermittedException();
|
throw new NoLoanPermittedException();
|
||||||
}
|
}
|
||||||
if (newBalance.compareTo(BigDecimal.ZERO) < 0 && !user.isAuthorized("essentials.eco.loan"))
|
if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan"))
|
||||||
{
|
{
|
||||||
throw new NoLoanPermittedException();
|
throw new NoLoanPermittedException();
|
||||||
}
|
}
|
||||||
user.setMoney(newBalance);
|
user.setMoney(balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds money to the balance of a user
|
* Adds money to the balance of a user
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @param amount The money you want to add
|
* @param amount The money you want to add
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void add(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
public static void add(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
{
|
{
|
||||||
double result = getMoney(name) + amount;
|
try
|
||||||
|
{
|
||||||
|
add(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void add(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
|
||||||
|
{
|
||||||
|
BigDecimal result = getMoneyExact(name).add(amount, MATH_CONTEXT);
|
||||||
setMoney(name, result);
|
setMoney(name, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Substracts money from the balance of a user
|
* Substracts money from the balance of a user
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @param amount The money you want to substract
|
* @param amount The money you want to substract
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void subtract(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
public static void subtract(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
{
|
{
|
||||||
double result = getMoney(name) - amount;
|
try
|
||||||
|
{
|
||||||
|
substract(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to substract " + amount + " of balance of " + name + ": " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void substract(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
|
||||||
|
{
|
||||||
|
BigDecimal result = getMoneyExact(name).subtract(amount, MATH_CONTEXT);
|
||||||
setMoney(name, result);
|
setMoney(name, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Divides the balance of a user by a value
|
* Divides the balance of a user by a value
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @param value The balance is divided by this value
|
* @param value The balance is divided by this value
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
*/
|
*/
|
||||||
public static void divide(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException
|
@Deprecated
|
||||||
|
public static void divide(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
{
|
{
|
||||||
double result = getMoney(name) / value;
|
try
|
||||||
|
{
|
||||||
|
divide(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void divide(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
|
||||||
|
{
|
||||||
|
BigDecimal result = getMoneyExact(name).divide(amount, MATH_CONTEXT);
|
||||||
setMoney(name, result);
|
setMoney(name, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiplies the balance of a user by a value
|
* Multiplies the balance of a user by a value
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @param value The balance is multiplied by this value
|
* @param value The balance is multiplied by this value
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
*/
|
*/
|
||||||
public static void multiply(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException
|
@Deprecated
|
||||||
|
public static void multiply(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
{
|
{
|
||||||
double result = getMoney(name) * value;
|
try
|
||||||
|
{
|
||||||
|
multiply(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void multiply(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
|
||||||
|
{
|
||||||
|
BigDecimal result = getMoneyExact(name).multiply(amount, MATH_CONTEXT);
|
||||||
setMoney(name, result);
|
setMoney(name, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the balance of a user to the starting balance
|
* Resets the balance of a user to the starting balance
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
|
||||||
@ -190,9 +268,23 @@ public final class Economy
|
|||||||
* @return true, if the user has more or an equal amount of money
|
* @return true, if the user has more or an equal amount of money
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean hasEnough(String name, double amount) throws UserDoesNotExistException
|
public static boolean hasEnough(String name, double amount) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
return amount <= getMoney(name);
|
try
|
||||||
|
{
|
||||||
|
return hasEnough(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasEnough(String name, BigDecimal amount) throws UserDoesNotExistException, ArithmeticException
|
||||||
|
{
|
||||||
|
return amount.compareTo(getMoneyExact(name)) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,9 +293,23 @@ public final class Economy
|
|||||||
* @return true, if the user has more money
|
* @return true, if the user has more money
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean hasMore(String name, double amount) throws UserDoesNotExistException
|
public static boolean hasMore(String name, double amount) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
return amount < getMoney(name);
|
try
|
||||||
|
{
|
||||||
|
return hasMore(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasMore(String name, BigDecimal amount) throws UserDoesNotExistException, ArithmeticException
|
||||||
|
{
|
||||||
|
return amount.compareTo(getMoneyExact(name)) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,39 +318,69 @@ public final class Economy
|
|||||||
* @return true, if the user has less money
|
* @return true, if the user has less money
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean hasLess(String name, double amount) throws UserDoesNotExistException
|
public static boolean hasLess(String name, double amount) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
return amount > getMoney(name);
|
try
|
||||||
|
{
|
||||||
|
return hasLess(name, BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (ArithmeticException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasLess(String name, BigDecimal amount) throws UserDoesNotExistException, ArithmeticException
|
||||||
|
{
|
||||||
|
return amount.compareTo(getMoneyExact(name)) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the user has a negative balance
|
* Test if the user has a negative balance
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @return true, if the user has a negative balance
|
* @return true, if the user has a negative balance
|
||||||
* @throws UserDoesNotExistException If a user by that name does not exists
|
* @throws UserDoesNotExistException If a user by that name does not exists
|
||||||
*/
|
*/
|
||||||
public static boolean isNegative(String name) throws UserDoesNotExistException
|
public static boolean isNegative(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
return getMoney(name) < 0.0;
|
return getMoneyExact(name).signum() < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the amount of money like all other Essentials functions.
|
* Formats the amount of money like all other Essentials functions. Example: $100000 or $12345.67
|
||||||
* Example: $100000 or $12345.67
|
*
|
||||||
* @param amount The amount of money
|
* @param amount The amount of money
|
||||||
* @return Formatted money
|
* @return Formatted money
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String format(double amount)
|
public static String format(double amount)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return format(BigDecimal.valueOf(amount));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.WARNING, "Failed to disply " + amount + ": " + e.getMessage(), e);
|
||||||
|
return "NaN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String format(BigDecimal amount)
|
||||||
{
|
{
|
||||||
if (ess == null)
|
if (ess == null)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(noCallBeforeLoad);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
return Util.displayCurrency(BigDecimal.valueOf(amount), ess);
|
return Util.displayCurrency(amount, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if a player exists to avoid the UserDoesNotExistException
|
* Test if a player exists to avoid the UserDoesNotExistException
|
||||||
|
*
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
* @return true, if the user exists
|
* @return true, if the user exists
|
||||||
*/
|
*/
|
||||||
@ -255,9 +391,10 @@ public final class Economy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if a player is a npc
|
* Test if a player is a npc
|
||||||
|
*
|
||||||
* @param name Name of the player
|
* @param name Name of the player
|
||||||
* @return true, if it's a npc
|
* @return true, if it's a npc
|
||||||
* @throws UserDoesNotExistException
|
* @throws UserDoesNotExistException
|
||||||
*/
|
*/
|
||||||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
@ -271,6 +408,7 @@ public final class Economy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates dummy files for a npc, if there is no player yet with that name.
|
* Creates dummy files for a npc, if there is no player yet with that name.
|
||||||
|
*
|
||||||
* @param name Name of the player
|
* @param name Name of the player
|
||||||
* @return true, if a new npc was created
|
* @return true, if a new npc was created
|
||||||
*/
|
*/
|
||||||
@ -286,9 +424,10 @@ public final class Economy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a user, if it is marked as npc.
|
* Deletes a user, if it is marked as npc.
|
||||||
|
*
|
||||||
* @param name Name of the player
|
* @param name Name of the player
|
||||||
* @throws UserDoesNotExistException
|
* @throws UserDoesNotExistException
|
||||||
*/
|
*/
|
||||||
public static void removeNPC(String name) throws UserDoesNotExistException
|
public static void removeNPC(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ public class Commandeco extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
Commandeco.EcoCommands cmd;
|
Commandeco.EcoCommands cmd;
|
||||||
BigDecimal startingBalance = new BigDecimal(ess.getSettings().getStartingBalance());
|
BigDecimal startingBalance = ess.getSettings().getStartingBalance();
|
||||||
BigDecimal amount;
|
BigDecimal amount;
|
||||||
BigDecimal broadcast = null;
|
BigDecimal broadcast = null;
|
||||||
BigDecimal broadcastAll = null;
|
BigDecimal broadcastAll = null;
|
||||||
|
@ -18,7 +18,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
public class EssentialsSign
|
public class EssentialsSign
|
||||||
{
|
{
|
||||||
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
||||||
|
protected static final BigDecimal MINTRANSACTION = new BigDecimal("0.01");
|
||||||
|
|
||||||
protected transient final String signName;
|
protected transient final String signName;
|
||||||
|
|
||||||
public EssentialsSign(final String signName)
|
public EssentialsSign(final String signName)
|
||||||
@ -68,8 +69,9 @@ public class EssentialsSign
|
|||||||
{
|
{
|
||||||
return _("signFormatTemplate", this.signName);
|
return _("signFormatTemplate", this.signName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return this.signName;
|
return this.signName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ public class EssentialsSign
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (!user.isDead() && (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
return (!user.isDead() && (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
||||||
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))))
|
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))))
|
||||||
&& onSignInteract(sign, user, getUsername(user), ess);
|
&& onSignInteract(sign, user, getUsername(user), ess);
|
||||||
}
|
}
|
||||||
catch (ChargeException ex)
|
catch (ChargeException ex)
|
||||||
@ -264,7 +266,7 @@ public class EssentialsSign
|
|||||||
{
|
{
|
||||||
return EMPTY_SET;
|
return EMPTY_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean areHeavyEventRequired()
|
public boolean areHeavyEventRequired()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -371,24 +373,28 @@ public class EssentialsSign
|
|||||||
protected final BigDecimal getMoney(final String line) throws SignException
|
protected final BigDecimal getMoney(final String line) throws SignException
|
||||||
{
|
{
|
||||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||||
return isMoney ? BigDecimal.valueOf(getDoublePositive(line.substring(1))) : null;
|
return isMoney ? getBigDecimalPositive(line.substring(1)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Double getDoublePositive(final String line) throws SignException
|
protected final BigDecimal getBigDecimalPositive(final String line) throws SignException
|
||||||
{
|
{
|
||||||
final double quantity = getDouble(line);
|
final BigDecimal quantity = getBigDecimal(line);
|
||||||
if (Math.round(quantity * 100.0) < 1.0)
|
if (quantity.compareTo(MINTRANSACTION) < 0)
|
||||||
{
|
{
|
||||||
throw new SignException(_("moreThanZero"));
|
throw new SignException(_("moreThanZero"));
|
||||||
}
|
}
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Double getDouble(final String line) throws SignException
|
protected final BigDecimal getBigDecimal(final String line) throws SignException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Double.parseDouble(line);
|
return new BigDecimal(line);
|
||||||
|
}
|
||||||
|
catch (ArithmeticException ex)
|
||||||
|
{
|
||||||
|
throw new SignException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
@ -468,7 +474,7 @@ public class EssentialsSign
|
|||||||
public final void setLine(final int index, final String text)
|
public final void setLine(final int index, final String text)
|
||||||
{
|
{
|
||||||
event.setLine(index, text);
|
event.setLine(index, text);
|
||||||
sign.setLine(index, text);
|
sign.setLine(index, text);
|
||||||
updateSign();
|
updateSign();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ public class SignTrade extends EssentialsSign
|
|||||||
{
|
{
|
||||||
super("Trade");
|
super("Trade");
|
||||||
}
|
}
|
||||||
static final BigDecimal MINTRANSACTION = BigDecimal.valueOf(0.01);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||||
@ -154,7 +153,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
if (split.length == 2 && amountNeeded)
|
if (split.length == 2 && amountNeeded)
|
||||||
{
|
{
|
||||||
final BigDecimal money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
BigDecimal amount = BigDecimal.valueOf(getDoublePositive(split[1]));
|
BigDecimal amount = getBigDecimalPositive(split[1]);
|
||||||
if (money != null && amount != null)
|
if (money != null && amount != null)
|
||||||
{
|
{
|
||||||
amount = amount.subtract(amount.remainder(money));
|
amount = amount.subtract(amount.remainder(money));
|
||||||
@ -223,7 +222,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
final BigDecimal money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
final BigDecimal amount = BigDecimal.valueOf(notEmpty ? getDoublePositive(split[1]) : getDouble(split[1]));
|
final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1]) : getBigDecimal(split[1]);
|
||||||
if (money != null && amount != null)
|
if (money != null && amount != null)
|
||||||
{
|
{
|
||||||
return new Trade(fullAmount ? amount : money, ess);
|
return new Trade(fullAmount ? amount : money, ess);
|
||||||
@ -270,17 +269,17 @@ public class SignTrade extends EssentialsSign
|
|||||||
final BigDecimal money = trade.getMoney();
|
final BigDecimal money = trade.getMoney();
|
||||||
if (money != null)
|
if (money != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, -money.doubleValue(), ess);
|
changeAmount(sign, index, money.negate(), ess);
|
||||||
}
|
}
|
||||||
final ItemStack item = trade.getItemStack();
|
final ItemStack item = trade.getItemStack();
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, -item.getAmount(), ess);
|
changeAmount(sign, index, BigDecimal.valueOf(-item.getAmount()), ess);
|
||||||
}
|
}
|
||||||
final Integer exp = trade.getExperience();
|
final Integer exp = trade.getExperience();
|
||||||
if (exp != null)
|
if (exp != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, -exp.intValue(), ess);
|
changeAmount(sign, index, BigDecimal.valueOf(-exp.intValue()), ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,22 +288,22 @@ public class SignTrade extends EssentialsSign
|
|||||||
final BigDecimal money = trade.getMoney();
|
final BigDecimal money = trade.getMoney();
|
||||||
if (money != null)
|
if (money != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, money.doubleValue(), ess);
|
changeAmount(sign, index, money, ess);
|
||||||
}
|
}
|
||||||
final ItemStack item = trade.getItemStack();
|
final ItemStack item = trade.getItemStack();
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, item.getAmount(), ess);
|
changeAmount(sign, index, BigDecimal.valueOf(item.getAmount()), ess);
|
||||||
}
|
}
|
||||||
final Integer exp = trade.getExperience();
|
final Integer exp = trade.getExperience();
|
||||||
if (exp != null)
|
if (exp != null)
|
||||||
{
|
{
|
||||||
changeAmount(sign, index, exp.intValue(), ess);
|
changeAmount(sign, index, BigDecimal.valueOf(exp.intValue()), ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Translate these exceptions.
|
//TODO: Translate these exceptions.
|
||||||
private void changeAmount(final ISign sign, final int index, final double value, final IEssentials ess) throws SignException
|
private void changeAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
|
|
||||||
final String line = sign.getLine(index).trim();
|
final String line = sign.getLine(index).trim();
|
||||||
@ -317,10 +316,10 @@ public class SignTrade extends EssentialsSign
|
|||||||
if (split.length == 2)
|
if (split.length == 2)
|
||||||
{
|
{
|
||||||
final BigDecimal money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
final BigDecimal amount = BigDecimal.valueOf(getDouble(split[1]));
|
final BigDecimal amount = getBigDecimal(split[1]);
|
||||||
if (money != null && amount != null)
|
if (money != null && amount != null)
|
||||||
{
|
{
|
||||||
final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount.add(BigDecimal.valueOf(value)), ess).substring(1);
|
final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount.add(value), ess).substring(1);
|
||||||
if (newline.length() > 15)
|
if (newline.length() > 15)
|
||||||
{
|
{
|
||||||
throw new SignException("This sign is full: Line too long!");
|
throw new SignException("This sign is full: Line too long!");
|
||||||
@ -336,7 +335,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
{
|
{
|
||||||
final int stackamount = getIntegerPositive(split[0]);
|
final int stackamount = getIntegerPositive(split[0]);
|
||||||
final int amount = getInteger(split[2]);
|
final int amount = getInteger(split[2]);
|
||||||
final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
|
final String newline = stackamount + " " + split[1] + ":" + (amount + value.intValueExact());
|
||||||
if (newline.length() > 15)
|
if (newline.length() > 15)
|
||||||
{
|
{
|
||||||
throw new SignException("This sign is full: Line too long!");
|
throw new SignException("This sign is full: Line too long!");
|
||||||
@ -350,7 +349,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
//TODO: Unused local variable
|
//TODO: Unused local variable
|
||||||
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
final ItemStack item = getItemStack(split[1], stackamount, ess);
|
||||||
final int amount = getInteger(split[2]);
|
final int amount = getInteger(split[2]);
|
||||||
final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
|
final String newline = stackamount + " " + split[1] + ":" + (amount + value.intValueExact());
|
||||||
if (newline.length() > 15)
|
if (newline.length() > 15)
|
||||||
{
|
{
|
||||||
throw new SignException("This sign is full: Line too long!");
|
throw new SignException("This sign is full: Line too long!");
|
||||||
|
@ -70,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 = 100.5;
|
BigDecimal i = new BigDecimal("100.5");
|
||||||
user.setMoney(BigDecimal.valueOf(i));
|
user.setMoney(i);
|
||||||
user.takeMoney(new BigDecimal(50));
|
user.takeMoney(new BigDecimal(50));
|
||||||
i -= 50;
|
i = i.subtract(BigDecimal.valueOf(50));
|
||||||
user.giveMoney(new BigDecimal(25));
|
user.giveMoney(new BigDecimal(25));
|
||||||
i += 25;
|
i = i.add(BigDecimal.valueOf(25));
|
||||||
assertEquals(user.getMoney().doubleValue(), i);
|
assertEquals(user.getMoney(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetGroup()
|
public void testGetGroup()
|
||||||
|
Loading…
Reference in New Issue
Block a user