mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
Add abbreviation support to /pay command (#5457)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
parent
0a4cf27342
commit
ad5f17481c
@ -18,6 +18,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandpay extends EssentialsLoopCommand {
|
||||
private static final BigDecimal THOUSAND = new BigDecimal(1000);
|
||||
private static final BigDecimal MILLION = new BigDecimal(1_000_000);
|
||||
private static final BigDecimal BILLION = new BigDecimal(1_000_000_000);
|
||||
private static final BigDecimal TRILLION = new BigDecimal(1_000_000_000_000L);
|
||||
|
||||
public Commandpay() {
|
||||
super("pay");
|
||||
}
|
||||
@ -28,17 +33,43 @@ public class Commandpay extends EssentialsLoopCommand {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
if (args[1].contains("-")) {
|
||||
final String ogStr = args[1];
|
||||
|
||||
if (ogStr.contains("-")) {
|
||||
throw new Exception(tl("payMustBePositive"));
|
||||
}
|
||||
|
||||
final String stringAmount = args[1].replaceAll("[^0-9\\.]", "");
|
||||
final String sanitizedString = ogStr.replaceAll("[^0-9.]", "");
|
||||
|
||||
if (stringAmount.length() < 1) {
|
||||
if (sanitizedString.isEmpty()) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final BigDecimal amount = new BigDecimal(stringAmount);
|
||||
BigDecimal tempAmount = new BigDecimal(sanitizedString);
|
||||
switch (Character.toLowerCase(ogStr.charAt(ogStr.length() - 1))) {
|
||||
case 'k': {
|
||||
tempAmount = tempAmount.multiply(THOUSAND);
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
tempAmount = tempAmount.multiply(MILLION);
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
tempAmount = tempAmount.multiply(BILLION);
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
tempAmount = tempAmount.multiply(TRILLION);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final BigDecimal amount = tempAmount;
|
||||
|
||||
if (amount.compareTo(ess.getSettings().getMinimumPayAmount()) < 0) { // Check if amount is less than minimum-pay-amount
|
||||
throw new Exception(tl("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user