Invalid Charge when using suffix currency
mmgfrcs opened this issue · 9 comments
So I think the shop signs does not play well with suffix currencies, because if I try to use signs with suffix currencies, it throws an error.
Information
Full output of /ess version
:
Server version: 1.14.4-R0.1-SNAPSHOT git-Paper-243 (MC: 1.14.4)
EssentialsX version: 2.17.2.77
LuckPerms version: 5.0.72
Vault version: 1.7.2-b107
PlaceholderAPI version: 2.10.6
EssentialsXChat version: 2.17.2.77
EssentialsXAntiBuild version: 2.17.2.77
Details
Steps to reproduce
- Enable buy/sell sign and set
currency-symbol-suffix
to true - Place a buy/sell sign of any item using currency cost, e.g
[Sell]
1
stone
$1
This will change to the following when "Done" is clicked:
[Sell]
1
stone
1$
- Use the sign
Expected behavior
For the example above, it should tell you in chat: "1$ has been added to your account"
Actual behavior
An error was shown: "Error: Invalid charge"
Errors in console
Activating debug mode, this is the error:
[14:27:05 INFO]: [Essentials] Error calling the command /\ sign: Sell
com.earth2me.essentials.signs.SignException: §4Invalid charge.
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:417) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:404) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:400) ~[?:?]
at com.earth2me.essentials.signs.SignSell.onSignInteract(SignSell.java:29) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.onSignInteract(EssentialsSign.java:117) ~[?:?]
at com.earth2me.essentials.signs.SignPlayerListener.onSignPlayerInteract(SignPlayerListener.java:61) ~[?:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor51.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.14.4.jar:git-Paper-243]
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.14.4.jar:git-Paper-243]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.14.4.jar:git-Paper-243]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:545) ~[patched_1.14.4.jar:git-Paper-243]
at org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:454) ~[patched_1.14.4.jar:git-Paper-243]
...
So looking at the stack trace and the code, I discovered the probable culprit:
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;
}
The regex only matches prefix currencies written on the sign:
This results in any suffix currencies returning null
. The code in getTrade
then tries to parse it as either usage cost, item cost or xp cost, which obviously will always fail, so any suffix currencies won't be able to use the sign.
I don't know whether this impacts all signs with cost, but I think it should be.
Should be fixed in #3253
Link to jar if you want to test: https://cdn.discordapp.com/attachments/480176903911636994/709064522257924106/EssentialsX-2.17.2.80.jar
Nope, not working
[15:38:39 INFO]: [Essentials] Trying resolver 'essentials:custom_items' for item 'stone'...
[15:38:39 INFO]: [Essentials] Error calling the command /\ sign: Sell
com.earth2me.essentials.signs.SignException: Character $ is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
at com.earth2me.essentials.signs.EssentialsSign.getBigDecimal(EssentialsSign.java:396) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getBigDecimalPositive(EssentialsSign.java:385) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getMoney(EssentialsSign.java:381) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:414) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:405) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.validateTrade(EssentialsSign.java:277) ~[?:?]
at com.earth2me.essentials.signs.SignSell.onSignCreate(SignSell.java:22) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.onSignCreate(EssentialsSign.java:58) ~[?:?]
at com.earth2me.essentials.signs.SignBlockListener.onSignSignChange(SignBlockListener.java:129) ~[?:?]
And all signs with cost are now broken apparently
That still didn't work.
This is the error it throws when using a prefix currency ($1):
com.earth2me.essentials.signs.SignException: null
at com.earth2me.essentials.signs.EssentialsSign.getBigDecimal(EssentialsSign.java:396) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getBigDecimalPositive(EssentialsSign.java:385) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getMoney(EssentialsSign.java:381) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:414) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:405) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:401) ~[?:?]
at com.earth2me.essentials.signs.SignSell.onSignInteract(SignSell.java:29) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.onSignInteract(EssentialsSign.java:117) ~[?:?]
at com.earth2me.essentials.signs.SignPlayerListener.onSignPlayerInteract(SignPlayerListener.java:61) ~[?:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor51.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.14.4.jar:git-Paper-243]
...
Caused by: java.lang.NumberFormatException
at java.math.BigDecimal.<init>(Unknown Source) ~[?:?]
at java.math.BigDecimal.<init>(Unknown Source) ~[?:?]
at java.math.BigDecimal.<init>(Unknown Source) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getBigDecimal(EssentialsSign.java:394) ~[?:?]
... 29 more
Caused by: java.lang.ArrayIndexOutOfBoundsException
and the suffix currency (1$):
[16:05:51] [Server thread/INFO]: [Essentials] Error calling the command /\ sign: Sell
com.earth2me.essentials.signs.SignException: §4Invalid charge.
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:418) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:405) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.getTrade(EssentialsSign.java:401) ~[?:?]
at com.earth2me.essentials.signs.SignSell.onSignInteract(SignSell.java:29) ~[?:?]
at com.earth2me.essentials.signs.EssentialsSign.onSignInteract(EssentialsSign.java:117) ~[?:?]
at com.earth2me.essentials.signs.SignPlayerListener.onSignPlayerInteract(SignPlayerListener.java:61) ~[?:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor51.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.14.4.jar:git-Paper-243]
...
Okay go ahead and give this one a try: https://cdn.discordapp.com/attachments/480176903911636994/709115038325145650/EssentialsX-2.17.2.80.jar
Pretty sure I fixed everything
The fix for this has now been merged - you can download the latest official version from the EssentialsX website.