mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-06 11:24:39 +08:00
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:
parent
8f88a8dcb3
commit
4b967a749b
@ -20,6 +20,7 @@ import static com.earth2me.essentials.I18n.tl;
|
|||||||
public class Commandeco extends EssentialsLoopCommand {
|
public class Commandeco extends EssentialsLoopCommand {
|
||||||
Commandeco.EcoCommands cmd;
|
Commandeco.EcoCommands cmd;
|
||||||
BigDecimal amount;
|
BigDecimal amount;
|
||||||
|
boolean isPercent;
|
||||||
|
|
||||||
public Commandeco() {
|
public Commandeco() {
|
||||||
super("eco");
|
super("eco");
|
||||||
@ -35,6 +36,7 @@ public class Commandeco extends EssentialsLoopCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
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\\.]", ""));
|
amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : new BigDecimal(args[2].replaceAll("[^0-9\\.]", ""));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new NotEnoughArgumentsException(ex);
|
throw new NotEnoughArgumentsException(ex);
|
||||||
@ -53,6 +55,9 @@ public class Commandeco extends EssentialsLoopCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws NotEnoughArgumentsException, ChargeException, MaxMoneyException {
|
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) {
|
switch (cmd) {
|
||||||
case GIVE:
|
case GIVE:
|
||||||
player.giveMoney(amount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
player.giveMoney(amount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
||||||
|
Loading…
Reference in New Issue
Block a user