mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-06 11:00:43 +01:00
Fix Trade signs
This commit is contained in:
parent
aef2ca3e5d
commit
e596f85953
@ -290,7 +290,7 @@ public class EssentialsSign
|
||||
protected final int getIntegerPositive(final String line) throws SignException
|
||||
{
|
||||
final int quantity = getInteger(line);
|
||||
if (quantity <= 1)
|
||||
if (quantity < 1)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
@ -328,19 +328,24 @@ public class EssentialsSign
|
||||
protected final Double getMoney(final String line) throws SignException
|
||||
{
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||
return isMoney ? getDouble(line.substring(1)) : null;
|
||||
return isMoney ? getDoublePositive(line.substring(1)) : null;
|
||||
}
|
||||
|
||||
protected final Double getDoublePositive(final String line) throws SignException
|
||||
{
|
||||
final double quantity = getDouble(line);
|
||||
if (quantity <= 0.0)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
protected final Double getDouble(final String line) throws SignException
|
||||
{
|
||||
try
|
||||
{
|
||||
final double quantity = Double.parseDouble(line);
|
||||
if (quantity <= 0.0)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
return quantity;
|
||||
return Double.parseDouble(line);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ public class SignTrade extends EssentialsSign
|
||||
{
|
||||
validateTrade(sign, 1, false, ess);
|
||||
validateTrade(sign, 2, true, ess);
|
||||
final Trade charge = getTrade(sign, 2, true, ess);
|
||||
final Trade charge = getTrade(sign, 2, true, true, ess);
|
||||
charge.isAffordableFor(player);
|
||||
sign.setLine(3, "§8" + username);
|
||||
charge.charge(player);
|
||||
@ -32,14 +32,14 @@ public class SignTrade extends EssentialsSign
|
||||
{
|
||||
if (sign.getLine(3).substring(2).equalsIgnoreCase(username))
|
||||
{
|
||||
final Trade stored = getTrade(sign, 1, true, ess);
|
||||
final Trade stored = getTrade(sign, 1, true, true, ess);
|
||||
substractAmount(sign, 1, stored);
|
||||
stored.pay(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Trade charge = getTrade(sign, 1, false, ess);
|
||||
final Trade trade = getTrade(sign, 2, false, ess);
|
||||
final Trade charge = getTrade(sign, 1, false, false, ess);
|
||||
final Trade trade = getTrade(sign, 2, false, true, ess);
|
||||
charge.isAffordableFor(player);
|
||||
substractAmount(sign, 2, trade);
|
||||
trade.pay(player);
|
||||
@ -54,8 +54,8 @@ public class SignTrade extends EssentialsSign
|
||||
{
|
||||
if (sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username))
|
||||
{
|
||||
final Trade stored1 = getTrade(sign, 1, true, ess);
|
||||
final Trade stored2 = getTrade(sign, 2, true, ess);
|
||||
final Trade stored1 = getTrade(sign, 1, true, false, ess);
|
||||
final Trade stored2 = getTrade(sign, 2, true, false, ess);
|
||||
stored1.pay(player);
|
||||
stored2.pay(player);
|
||||
return true;
|
||||
@ -88,7 +88,7 @@ public class SignTrade extends EssentialsSign
|
||||
if (split.length == 2 && amountNeeded)
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
final Double amount = getDouble(split[1]);
|
||||
final Double amount = getDoublePositive(split[1]);
|
||||
if (money != null && amount != null)
|
||||
{
|
||||
sign.setLine(index, Util.formatCurrency(money) + ":" + Util.formatCurrency(amount).substring(1));
|
||||
@ -124,7 +124,7 @@ public class SignTrade extends EssentialsSign
|
||||
throw new SignException(Util.format("invalidSignLine", index));
|
||||
}
|
||||
|
||||
protected final Trade getTrade(final ISign sign, final int index, final boolean fullAmount, final IEssentials ess) throws SignException
|
||||
protected final Trade getTrade(final ISign sign, final int index, final boolean fullAmount, final boolean notEmpty, final IEssentials ess) throws SignException
|
||||
{
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty())
|
||||
@ -136,7 +136,7 @@ public class SignTrade extends EssentialsSign
|
||||
if (split.length == 2)
|
||||
{
|
||||
final Double money = getMoney(split[0]);
|
||||
final Double amount = getDouble(split[1]);
|
||||
final Double amount = notEmpty ? getDoublePositive(split[1]) : getDouble(split[1]);
|
||||
if (money != null && amount != null)
|
||||
{
|
||||
return new Trade(fullAmount ? amount : money, ess);
|
||||
@ -147,9 +147,9 @@ public class SignTrade extends EssentialsSign
|
||||
{
|
||||
final int stackamount = getIntegerPositive(split[0]);
|
||||
final ItemStack item = getItemStack(split[1], stackamount);
|
||||
int amount = getIntegerPositive(split[2]);
|
||||
int amount = getInteger(split[2]);
|
||||
amount -= amount % stackamount;
|
||||
if (amount < 1 || stackamount < 1 || item.getTypeId() == 0)
|
||||
if (notEmpty && (amount < 1 || stackamount < 1 || item.getTypeId() == 0))
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user