Added a command to /eco that allows users to take percentages from pl… (#3080)

* Removed unnecessary formatting

* Fixed spacing around isPercent, removed unnecessary parenthesis, optimized conversion
This commit is contained in:
Crash Cringle 2020-05-13 00:38:36 -04:00 committed by GitHub
parent 8f88a8dcb3
commit 4b967a749b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import static com.earth2me.essentials.I18n.tl;
public class Commandeco extends EssentialsLoopCommand {
Commandeco.EcoCommands cmd;
BigDecimal amount;
boolean isPercent;
public Commandeco() {
super("eco");
@ -35,6 +36,7 @@ public class Commandeco extends EssentialsLoopCommand {
try {
cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
isPercent = args[2].endsWith("%");
amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : new BigDecimal(args[2].replaceAll("[^0-9\\.]", ""));
} catch (Exception ex) {
throw new NotEnoughArgumentsException(ex);
@ -53,6 +55,9 @@ public class Commandeco extends EssentialsLoopCommand {
@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws NotEnoughArgumentsException, ChargeException, MaxMoneyException {
if (isPercent && cmd != EcoCommands.RESET) {
amount = player.getMoney().multiply(amount).scaleByPowerOfTen(-2);
}
switch (cmd) {
case GIVE:
player.giveMoney(amount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO);