mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-21 22:06:22 +02:00
Further economy cleanup
This commit is contained in:
@@ -27,6 +27,7 @@ public class Trade
|
|||||||
private final transient Integer exp;
|
private final transient Integer exp;
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
|
|
||||||
public enum TradeType
|
public enum TradeType
|
||||||
{
|
{
|
||||||
MONEY,
|
MONEY,
|
||||||
@@ -49,11 +50,6 @@ public class Trade
|
|||||||
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);
|
||||||
@@ -222,7 +218,8 @@ public class Trade
|
|||||||
|
|
||||||
public TradeType getType()
|
public TradeType getType()
|
||||||
{
|
{
|
||||||
if (getExperience() != null) {
|
if (getExperience() != null)
|
||||||
|
{
|
||||||
return TradeType.EXP;
|
return TradeType.EXP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -522,7 +522,6 @@ public class Util
|
|||||||
}
|
}
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 BigDecimal value)
|
public static String formatAsCurrency(final BigDecimal value)
|
||||||
@@ -546,11 +545,6 @@ public class Util
|
|||||||
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
|
||||||
|
@@ -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]+$");
|
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
|
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);
|
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Double money = getMoney(line);
|
final BigDecimal money = getMoney(line);
|
||||||
if (money == null)
|
if (money == null)
|
||||||
{
|
{
|
||||||
final String[] split = line.split("[ :]+", 2);
|
final String[] split = line.split("[ :]+", 2);
|
||||||
|
@@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
//TODO: TL exceptions
|
//TODO: TL exceptions
|
||||||
public class SignTrade extends EssentialsSign
|
public class SignTrade extends EssentialsSign
|
||||||
{
|
{
|
||||||
|
|
||||||
public SignTrade()
|
public SignTrade()
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -22,7 +22,8 @@ public class SignTrade extends EssentialsSign
|
|||||||
validateTrade(sign, 2, true, ess);
|
validateTrade(sign, 2, true, ess);
|
||||||
final Trade trade = getTrade(sign, 2, true, true, ess);
|
final Trade trade = getTrade(sign, 2, true, true, ess);
|
||||||
final Trade charge = getTrade(sign, 1, true, false, 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.");
|
throw new SignException("You cannot trade for the same item type.");
|
||||||
}
|
}
|
||||||
trade.isAffordableFor(player);
|
trade.isAffordableFor(player);
|
||||||
@@ -138,7 +139,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
|
|
||||||
if (split.length == 1 && !amountNeeded)
|
if (split.length == 1 && !amountNeeded)
|
||||||
{
|
{
|
||||||
final Double money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
if (money != null)
|
if (money != null)
|
||||||
{
|
{
|
||||||
if (Util.shortCurrency(money, ess).length() * 2 > 15)
|
if (Util.shortCurrency(money, ess).length() * 2 > 15)
|
||||||
@@ -152,12 +153,12 @@ public class SignTrade extends EssentialsSign
|
|||||||
|
|
||||||
if (split.length == 2 && amountNeeded)
|
if (split.length == 2 && amountNeeded)
|
||||||
{
|
{
|
||||||
final Double money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
Double amount = getDoublePositive(split[1]);
|
BigDecimal amount = BigDecimal.valueOf(getDoublePositive(split[1]));
|
||||||
if (money != null && amount != null)
|
if (money != null && amount != null)
|
||||||
{
|
{
|
||||||
amount -= amount % money;
|
amount = amount.subtract(amount.remainder(money));
|
||||||
if (amount < 0.01 || money < 0.01)
|
if (amount.compareTo(MINTRANSACTION) < 0 || money.compareTo(MINTRANSACTION) < 0)
|
||||||
{
|
{
|
||||||
throw new SignException(_("moreThanZero"));
|
throw new SignException(_("moreThanZero"));
|
||||||
}
|
}
|
||||||
@@ -221,8 +222,8 @@ public class SignTrade extends EssentialsSign
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final Double money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
final Double amount = notEmpty ? getDoublePositive(split[1]) : getDouble(split[1]);
|
final BigDecimal amount = BigDecimal.valueOf(notEmpty ? getDoublePositive(split[1]) : getDouble(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);
|
||||||
@@ -315,11 +316,11 @@ public class SignTrade extends EssentialsSign
|
|||||||
|
|
||||||
if (split.length == 2)
|
if (split.length == 2)
|
||||||
{
|
{
|
||||||
final Double money = getMoney(split[0]);
|
final BigDecimal money = getMoney(split[0]);
|
||||||
final Double amount = getDouble(split[1]);
|
final BigDecimal amount = BigDecimal.valueOf(getDouble(split[1]));
|
||||||
if (money != null && amount != null)
|
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)
|
if (newline.length() > 15)
|
||||||
{
|
{
|
||||||
throw new SignException("This sign is full: Line too long!");
|
throw new SignException("This sign is full: Line too long!");
|
||||||
|
Reference in New Issue
Block a user