mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-19 09:06:09 +01:00
Further economy cleanup
This commit is contained in:
parent
162b67aaa6
commit
c4ac744d35
@ -26,14 +26,15 @@ public class Trade
|
||||
private final transient ItemStack itemStack;
|
||||
private final transient Integer exp;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
|
||||
|
||||
public enum TradeType
|
||||
{
|
||||
MONEY,
|
||||
EXP,
|
||||
ITEM
|
||||
}
|
||||
|
||||
|
||||
public Trade(final String command, final IEssentials ess)
|
||||
{
|
||||
this(command, null, null, null, null, ess);
|
||||
@ -48,11 +49,6 @@ public class Trade
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -219,10 +215,11 @@ public class Trade
|
||||
{
|
||||
return exp;
|
||||
}
|
||||
|
||||
|
||||
public TradeType getType()
|
||||
{
|
||||
if (getExperience() != null) {
|
||||
if (getExperience() != null)
|
||||
{
|
||||
return TradeType.EXP;
|
||||
}
|
||||
|
||||
@ -231,7 +228,7 @@ public class Trade
|
||||
return TradeType.ITEM;
|
||||
}
|
||||
|
||||
return TradeType.MONEY;
|
||||
return TradeType.MONEY;
|
||||
}
|
||||
|
||||
public BigDecimal getCommandCost(final IUser user)
|
||||
@ -251,7 +248,7 @@ public class Trade
|
||||
}
|
||||
}
|
||||
if (cost.compareTo(BigDecimal.ZERO) != 0 && (user.isAuthorized("essentials.nocommandcost.all")
|
||||
|| user.isAuthorized("essentials.nocommandcost." + command)))
|
||||
|| user.isAuthorized("essentials.nocommandcost." + command)))
|
||||
{
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
@ -263,7 +260,7 @@ public class Trade
|
||||
{
|
||||
//isEcoLogUpdateEnabled() - This refers to log entries with no location, ie API updates #EasterEgg
|
||||
//isEcoLogEnabled() - This refers to log entries with with location, ie /pay /sell and eco signs.
|
||||
|
||||
|
||||
if ((loc == null && !ess.getSettings().isEcoLogUpdateEnabled())
|
||||
|| (loc != null && !ess.getSettings().isEcoLogEnabled()))
|
||||
{
|
||||
|
@ -522,7 +522,6 @@ public class Util
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
private static DecimalFormat dFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public static String formatAsCurrency(final BigDecimal value)
|
||||
@ -540,16 +539,11 @@ public class Util
|
||||
{
|
||||
return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value));
|
||||
}
|
||||
|
||||
|
||||
public static String shortCurrency(final BigDecimal value, final IEssentials ess)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -368,10 +368,10 @@ public class EssentialsSign
|
||||
}
|
||||
}
|
||||
|
||||
protected final Double getMoney(final String line) throws SignException
|
||||
protected final BigDecimal getMoney(final String line) throws SignException
|
||||
{
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||
return isMoney ? getDoublePositive(line.substring(1)) : null;
|
||||
return isMoney ? BigDecimal.valueOf(getDoublePositive(line.substring(1))) : null;
|
||||
}
|
||||
|
||||
protected final Double getDoublePositive(final String line) throws SignException
|
||||
@ -409,7 +409,7 @@ public class EssentialsSign
|
||||
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
||||
}
|
||||
|
||||
final Double money = getMoney(line);
|
||||
final BigDecimal money = getMoney(line);
|
||||
if (money == null)
|
||||
{
|
||||
final String[] split = line.split("[ :]+", 2);
|
||||
|
@ -8,12 +8,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
//TODO: TL exceptions
|
||||
public class SignTrade extends EssentialsSign
|
||||
{
|
||||
|
||||
{
|
||||
public SignTrade()
|
||||
{
|
||||
super("Trade");
|
||||
}
|
||||
static final BigDecimal MINTRANSACTION = BigDecimal.valueOf(0.01);
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
@ -22,7 +22,8 @@ public class SignTrade extends EssentialsSign
|
||||
validateTrade(sign, 2, true, ess);
|
||||
final Trade trade = getTrade(sign, 2, true, true, ess);
|
||||
final Trade charge = getTrade(sign, 1, true, false, ess);
|
||||
if (trade.getType() == charge.getType() && (trade.getType() != TradeType.ITEM || trade.getItemStack().getType().equals(charge.getItemStack().getType()))) {
|
||||
if (trade.getType() == charge.getType() && (trade.getType() != TradeType.ITEM || trade.getItemStack().getType().equals(charge.getItemStack().getType())))
|
||||
{
|
||||
throw new SignException("You cannot trade for the same item type.");
|
||||
}
|
||||
trade.isAffordableFor(player);
|
||||
@ -138,7 +139,7 @@ public class SignTrade extends EssentialsSign
|
||||
|
||||
if (split.length == 1 && !amountNeeded)
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
if (money != null)
|
||||
{
|
||||
if (Util.shortCurrency(money, ess).length() * 2 > 15)
|
||||
@ -152,12 +153,12 @@ public class SignTrade extends EssentialsSign
|
||||
|
||||
if (split.length == 2 && amountNeeded)
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
Double amount = getDoublePositive(split[1]);
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
BigDecimal amount = BigDecimal.valueOf(getDoublePositive(split[1]));
|
||||
if (money != null && amount != null)
|
||||
{
|
||||
amount -= amount % money;
|
||||
if (amount < 0.01 || money < 0.01)
|
||||
amount = amount.subtract(amount.remainder(money));
|
||||
if (amount.compareTo(MINTRANSACTION) < 0 || money.compareTo(MINTRANSACTION) < 0)
|
||||
{
|
||||
throw new SignException(_("moreThanZero"));
|
||||
}
|
||||
@ -221,8 +222,8 @@ public class SignTrade extends EssentialsSign
|
||||
{
|
||||
try
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
final Double amount = notEmpty ? getDoublePositive(split[1]) : getDouble(split[1]);
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal amount = BigDecimal.valueOf(notEmpty ? getDoublePositive(split[1]) : getDouble(split[1]));
|
||||
if (money != null && amount != null)
|
||||
{
|
||||
return new Trade(fullAmount ? amount : money, ess);
|
||||
@ -315,11 +316,11 @@ public class SignTrade extends EssentialsSign
|
||||
|
||||
if (split.length == 2)
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
final Double amount = getDouble(split[1]);
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal amount = BigDecimal.valueOf(getDouble(split[1]));
|
||||
if (money != null && amount != null)
|
||||
{
|
||||
final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount + value, ess).substring(1);
|
||||
final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount.add(BigDecimal.valueOf(value)), ess).substring(1);
|
||||
if (newline.length() > 15)
|
||||
{
|
||||
throw new SignException("This sign is full: Line too long!");
|
||||
|
Loading…
Reference in New Issue
Block a user