mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +00:00
Improve currency validation in signs (#3987)
Sanitise currency strings in more cases when handling signs. Should fix #3979.
This commit is contained in:
parent
0ce4029483
commit
1cf2b11f1e
2 changed files with 10 additions and 10 deletions
|
@ -393,20 +393,20 @@ public class EssentialsSign {
|
|||
|
||||
protected final BigDecimal getMoney(final String line, final IEssentials ess) throws SignException {
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.]?[\\.0-9]+[^0-9-\\.]?$");
|
||||
return isMoney ? getBigDecimalPositive(NumberUtil.sanitizeCurrencyString(line, ess)) : null;
|
||||
return isMoney ? getBigDecimalPositive(line, ess) : null;
|
||||
}
|
||||
|
||||
protected final BigDecimal getBigDecimalPositive(final String line) throws SignException {
|
||||
final BigDecimal quantity = getBigDecimal(line);
|
||||
protected final BigDecimal getBigDecimalPositive(final String line, final IEssentials ess) throws SignException {
|
||||
final BigDecimal quantity = getBigDecimal(line, ess);
|
||||
if (quantity.compareTo(MINTRANSACTION) < 0) {
|
||||
throw new SignException(tl("moreThanZero"));
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
protected final BigDecimal getBigDecimal(final String line) throws SignException {
|
||||
protected final BigDecimal getBigDecimal(final String line, final IEssentials ess) throws SignException {
|
||||
try {
|
||||
return new BigDecimal(line);
|
||||
return new BigDecimal(NumberUtil.sanitizeCurrencyString(line, ess));
|
||||
} catch (final ArithmeticException | NumberFormatException ex) {
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ public class SignTrade extends EssentialsSign {
|
|||
|
||||
if (split.length == 2 && amountNeeded) {
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
BigDecimal amount = getBigDecimalPositive(split[1]);
|
||||
BigDecimal amount = getBigDecimalPositive(split[1], ess);
|
||||
if (money != null && amount != null) {
|
||||
amount = amount.subtract(amount.remainder(money));
|
||||
if (amount.compareTo(MINTRANSACTION) < 0 || money.compareTo(MINTRANSACTION) < 0) {
|
||||
|
@ -219,7 +219,7 @@ public class SignTrade extends EssentialsSign {
|
|||
if (split.length == 2) {
|
||||
try {
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1]) : getBigDecimal(split[1]);
|
||||
final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1], ess) : getBigDecimal(split[1], ess);
|
||||
if (money != null && amount != null) {
|
||||
return new Trade(amountType == AmountType.COST ? money : amount, ess);
|
||||
}
|
||||
|
@ -295,12 +295,12 @@ public class SignTrade extends EssentialsSign {
|
|||
final String[] split = line.split("[ :]+");
|
||||
|
||||
if (split.length == 2) {
|
||||
final BigDecimal amount = getBigDecimal(split[1]).add(value);
|
||||
final BigDecimal amount = getBigDecimal(split[1], ess).add(value);
|
||||
setAmount(sign, index, amount, ess);
|
||||
return;
|
||||
}
|
||||
if (split.length == 3) {
|
||||
final BigDecimal amount = getBigDecimal(split[2]).add(value);
|
||||
final BigDecimal amount = getBigDecimal(split[2], ess).add(value);
|
||||
setAmount(sign, index, amount, ess);
|
||||
return;
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ public class SignTrade extends EssentialsSign {
|
|||
|
||||
if (split.length == 2) {
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
final BigDecimal amount = getBigDecimal(split[1]);
|
||||
final BigDecimal amount = getBigDecimal(split[1], ess);
|
||||
if (money != null && amount != null) {
|
||||
final String newline = NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(value, ess).substring(1);
|
||||
if (newline.length() > 15) {
|
||||
|
|
Loading…
Reference in a new issue