EssentialsX

EssentialsX

2M Downloads

/pay uses wrong currency format (decimals)

robinstiege opened this issue ยท 2 comments

commented

Information

Full output of /ess version:

[15:30:20 INFO]: Server Version: 1.12.2-R0.1-SNAPSHOT git-Spigot-dcd1643-e60fc34 (MC: 1.12.2)
[15:30:20 INFO]: EssentialsX Version: 2.16.0.6
[15:30:20 INFO]: LuckPerms Version: 4.3.17
[15:30:20 INFO]: Vault Version: 1.7.1-b91
[15:30:20 INFO]: EssentialsXSpawn Version: 2.16.0.6

EssentialsX config: https://gist.github.com/StiegeRobin/71f4c04d9df8aa123d96a4bc79538ca3

Details

Description
The command /pay doesn't take care of the currency-symbol-format-locale setting. When a player want to pay 50 cents seperated with a comma (like it's also displayed with /money), they will pay 50 euro instead.

Steps to reproduce

  1. Change the currency-symbol-format-locale to de-DE
  2. Change the minimum-pay-amount to at least 0.01
  3. Do /ess reload
  4. Pay someone a german formatted amount of money like /pay User 100,50 (these are 100 euro and 50 cents)
  5. You will see that you've paid 1.005,00 to that User instead of 100,50.

Expected behavior
As I've changed the currency format to german, the /pay command should also utilize it.

commented

Thanks for opening a bug report.

EssentialsX currently removes all characters except the digits 0-9 and a decimal point:

String stringAmount = args[1].replaceAll("[^0-9\\.]", "");

It then uses Java's BigDecimal to parse the resulting amount into an actual money value:

It's the second part that's the issue - BigDecimal doesn't support , decimal places. Even if we stopped removing commas, we'd need to parse the command argument ourselves in order to solve this.

While this can't be fixed immediately, for now you can enable command confirmations, which will prompt users to type /pay confirm before sending money, prompting them with the correct amount (shown in the right currency format) before the payment is sent.

commented

Okay, I understand the problem. I tried the following:

String stringAmount = "1.234XYZ,50".replaceAll("[^0-9\\.\\,]", "");
BigDecimal bigDecimal = new BigDecimal(NumberFormat.getNumberInstance(Locale.GERMAN).parse(stringAmount).toString());
System.out.println(bigDecimal);

This gives me 1234.5 when I put "1.23XYZ4,50" and should be okay for further use.