mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Fix invalid charge error when using suffix currency on signs (#3253)
i swear i test my code Fixes #3252.
This commit is contained in:
parent
fc2b7b63a2
commit
61d0ed3f01
4 changed files with 19 additions and 10 deletions
|
@ -7,6 +7,7 @@ import com.earth2me.essentials.textreader.IText;
|
|||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.KitClaimEvent;
|
||||
|
||||
|
@ -160,11 +161,10 @@ public class Kit {
|
|||
boolean spew = false;
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
final boolean currencyIsSuffix = ess.getSettings().isCurrencySymbolSuffixed();
|
||||
final String currencySymbol = ess.getSettings().getCurrencySymbol();
|
||||
List<ItemStack> itemList = new ArrayList<>();
|
||||
for (String kitItem : output.getLines()) {
|
||||
if (!currencyIsSuffix ? kitItem.startsWith(ess.getSettings().getCurrencySymbol()) : kitItem.endsWith(ess.getSettings().getCurrencySymbol())) {
|
||||
final String valueString = currencyIsSuffix ? kitItem.substring(0, currencySymbol.length()) : kitItem.substring(currencySymbol.length());
|
||||
final String valueString = NumberUtil.sanitizeCurrencyString(kitItem, ess);
|
||||
BigDecimal value = new BigDecimal(valueString.trim());
|
||||
Trade t = new Trade(value, ess);
|
||||
t.pay(user, OverflowType.DROP);
|
||||
|
|
|
@ -375,9 +375,9 @@ public class EssentialsSign {
|
|||
return stack;
|
||||
}
|
||||
|
||||
protected final BigDecimal getMoney(final String line) throws SignException {
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||
return isMoney ? getBigDecimalPositive(line.substring(1)) : null;
|
||||
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;
|
||||
}
|
||||
|
||||
protected final BigDecimal getBigDecimalPositive(final String line) throws SignException {
|
||||
|
@ -410,7 +410,7 @@ public class EssentialsSign {
|
|||
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
||||
}
|
||||
|
||||
final BigDecimal money = getMoney(line);
|
||||
final BigDecimal money = getMoney(line, ess);
|
||||
if (money == null) {
|
||||
final String[] split = line.split("[ :]+", 2);
|
||||
if (split.length != 2) {
|
||||
|
|
|
@ -149,7 +149,7 @@ public class SignTrade extends EssentialsSign {
|
|||
final String[] split = line.split("[ :]+");
|
||||
|
||||
if (split.length == 1 && !amountNeeded) {
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
if (money != null) {
|
||||
if (NumberUtil.shortCurrency(money, ess).length() * 2 > 15) {
|
||||
throw new SignException("Line can be too long!");
|
||||
|
@ -160,7 +160,7 @@ public class SignTrade extends EssentialsSign {
|
|||
}
|
||||
|
||||
if (split.length == 2 && amountNeeded) {
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
BigDecimal amount = getBigDecimalPositive(split[1]);
|
||||
if (money != null && amount != null) {
|
||||
amount = amount.subtract(amount.remainder(money));
|
||||
|
@ -218,7 +218,7 @@ public class SignTrade extends EssentialsSign {
|
|||
|
||||
if (split.length == 2) {
|
||||
try {
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1]) : getBigDecimal(split[1]);
|
||||
if (money != null && amount != null) {
|
||||
return new Trade(amountType == AmountType.COST ? money : amount, ess);
|
||||
|
@ -317,7 +317,7 @@ public class SignTrade extends EssentialsSign {
|
|||
final String[] split = line.split("[ :]+");
|
||||
|
||||
if (split.length == 2) {
|
||||
final BigDecimal money = getMoney(split[0]);
|
||||
final BigDecimal money = getMoney(split[0], ess);
|
||||
final BigDecimal amount = getBigDecimal(split[1]);
|
||||
if (money != null && amount != null) {
|
||||
final String newline = NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(value, ess).substring(1);
|
||||
|
|
|
@ -88,6 +88,15 @@ public class NumberUtil {
|
|||
return sign + tl("currency", ess.getSettings().getCurrencySymbol(), currency);
|
||||
}
|
||||
|
||||
public static String sanitizeCurrencyString(final String input, final IEssentials ess) {
|
||||
String symbol = ess.getSettings().getCurrencySymbol();
|
||||
boolean suffix = ess.getSettings().isCurrencySymbolSuffixed();
|
||||
if (input.contains(symbol)) {
|
||||
return suffix ? input.substring(0, input.indexOf(symbol)) : input.substring(symbol.length());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static boolean isInt(final String sInt) {
|
||||
try {
|
||||
Integer.parseInt(sInt);
|
||||
|
|
Loading…
Reference in a new issue