EssentialsX

EssentialsX

2M Downloads

/pay comma handling

Kakifrucht opened this issue ยท 16 comments

commented

Decimals are seperated via comma in many countries. Right now, they get stripped. If a user uses /pay player 1,50, player will get 150 instead. This should not happen.
I propose to just print an error on , usage, since just replacing it could cause trouble for people using the other number system.

commented

My suggestion was to allow for customising the regex used, but this would mean that the usage info would become invalid if it wasn't also localised.

commented

That wouldn't be intuitive though. Better yes, but not intuitive for other people.

commented

If a custom regex was implemented, EssentialsX would most likely have to provide examples. Another idea could be allowing a default decimal separator to be set in the config, and allowing each user to override this if so desired (for example, someone from the UK playing on a German server would be able to specify that their preferred decimal separator is . and not ,).

commented

You wouldn't be able to use both as separators anyway; in many places which use . as the decimal separator, , is used as the thousands separator, so there might not necessarily be a way to know whether 3,000 meant 3 (three) or 3*(10^2) (three thousand).

commented

But would that work if you want to allow both . and , as seperators?

commented

I'm really unsure myself what would be the best way. Technically, I don't think that anyone uses a seperator when using /pay. I myself am a bit inconsistent when it comes to number format, where I use seperator and comma here and on the other display just the normal double output with a '.' as decimal seperator. That's why I would like to allow both . and , to be used, but I understand that it might cause issues for other people.

commented

It's quite simple to think about, less so to implement. We already have a
currency locale that we use to format currency. We should just use that to
handle user input.

With that said it's not that simple to implement I don't think. I'll need
to look at whether java has a way to parse a string as a number.

On 22 Nov 2016 14:28, "Fabian" [email protected] wrote:

I'm really unsure myself what would be the best way. Technically, I don't
think that anyone uses a seperator when using /pay. I myself am a bit
inconsistent when it comes to number format, where I use seperator and
comma here and on the other display just the normal double output with a
'.' as decimal seperator. That's why I would like to allow both . and , to
be used, but I understand that it might cause issues for other people.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#977 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPV0bRf8zt0YkMhz6LW14Ym6H6T_ZVCks5rAvwAgaJpZM4K4wlr
.

commented

I don't know, I think that wouldn't be optimal either to take the current locale. I still feel like the best method would be to just keep the default '.' as decimal seperator, replace all commas with '.' and then strip all '.''s after the first placed one. This would not disrupt the behaviour for people who use it that way already, even in countries where the comma is used as seperator while not causing the sending of wrong amounts (only smaller amounts than originally intended). And it is easy to implement.
Most players on my server know to use '.' instead of comma, but people who don't will send an amount 10 times higher, which really shouldn't be possible.

commented

My quickly sketched solution (didn't test, probably index errors), add here:

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

int index = stringAmount.indexOf('.');
if (index > 0) {
    String amountSplit = stringAmount.substring(0, index);
    stringAmount = amountSplit + stringAmount.substring(index + 1).replaceAll(".", "");
}
commented

I just realised something. /pay has no confirmation message. So if I type /pay kakifrucht 1000000 with one too many 0s, I could basically go broke.

What if when you pay someone money, essx asks you to confirm this payment with the amount formatted as per the server's currency formatting.

So if UK:

  1. pay kaki 1000 says "To confirm payment of $1,000.00 to kakifrucht please repeat command."
  2. pay kaki 1.000 or pay kaki 1,000 says "To confirm payment of $1.00 to kakifrucht please repeat command."

If germany or something:

  1. pay kaki 1000 says "To confirm payment of $1.000,00 to kakifrucht please repeat command."
  2. pay kaki 1,000 or pay kaki 1.000 says "To confirm payment of $1,00 to kakifrucht please repeat command."
commented

That would be completely fine by me aswell.

commented

@SupaHam @md678685 thoughts on my proposed implementation?

commented

I'll start implementing this now in a PR.

commented

This has been introduced in dadc6b2. You can grab the feature from build 459 on the CI server.

commented

Do we really need to even have comma separators....

commented

We don't need to, and we don't even.