mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-12-24 13:31:05 +01:00
fix(bukkit): remove max value from commands
This commit is contained in:
parent
4c832f11f1
commit
ca5086621b
5 changed files with 8 additions and 31 deletions
|
@ -7,7 +7,6 @@ import dev.jorel.commandapi.arguments.OfflinePlayerArgument;
|
|||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||
import dev.xhyrom.lighteco.bukkit.util.Util;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -28,8 +27,8 @@ public class GiveCommand implements Command {
|
|||
.withArguments(
|
||||
new OfflinePlayerArgument("target"),
|
||||
currency.getProxy().fractionalDigits() > 0
|
||||
? new DoubleArgument("amount", 1, Util.bigDecimalToDouble(this.manager.plugin.getConfig().maximumBalance))
|
||||
: new IntegerArgument("amount", 1, this.manager.plugin.getConfig().maximumBalance.intValue())
|
||||
? new DoubleArgument("amount", 1)
|
||||
: new IntegerArgument("amount", 1)
|
||||
)
|
||||
.executes((sender, args) -> {
|
||||
this.handleGive(sender, args, currency);
|
||||
|
|
|
@ -7,7 +7,6 @@ import dev.jorel.commandapi.arguments.OfflinePlayerArgument;
|
|||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||
import dev.xhyrom.lighteco.bukkit.util.Util;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -28,8 +27,8 @@ public class PayCommand implements Command {
|
|||
.withArguments(
|
||||
new OfflinePlayerArgument("target"),
|
||||
currency.getProxy().fractionalDigits() > 0
|
||||
? new DoubleArgument("amount", 1, Util.bigDecimalToDouble(this.manager.plugin.getConfig().maximumBalance))
|
||||
: new IntegerArgument("amount", 1, this.manager.plugin.getConfig().maximumBalance.intValue())
|
||||
? new DoubleArgument("amount", 1)
|
||||
: new IntegerArgument("amount", 1)
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
this.handlePay(sender, args, currency);
|
||||
|
|
|
@ -7,7 +7,6 @@ import dev.jorel.commandapi.arguments.OfflinePlayerArgument;
|
|||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||
import dev.xhyrom.lighteco.bukkit.util.Util;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -28,8 +27,8 @@ public class SetCommand implements Command {
|
|||
.withArguments(
|
||||
new OfflinePlayerArgument("target"),
|
||||
currency.getProxy().fractionalDigits() > 0
|
||||
? new DoubleArgument("amount", 0, Util.bigDecimalToDouble(this.manager.plugin.getConfig().maximumBalance))
|
||||
: new IntegerArgument("amount", 0, this.manager.plugin.getConfig().maximumBalance.intValue())
|
||||
? new DoubleArgument("amount", 0)
|
||||
: new IntegerArgument("amount", 0)
|
||||
)
|
||||
.executes((sender, args) -> {
|
||||
this.handleSet(sender, args, currency);
|
||||
|
|
|
@ -7,7 +7,6 @@ import dev.jorel.commandapi.arguments.OfflinePlayerArgument;
|
|||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||
import dev.xhyrom.lighteco.bukkit.util.Util;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -28,8 +27,8 @@ public class TakeCommand implements Command {
|
|||
.withArguments(
|
||||
new OfflinePlayerArgument("target"),
|
||||
currency.getProxy().fractionalDigits() > 0
|
||||
? new DoubleArgument("amount", 1, Util.bigDecimalToDouble(this.manager.plugin.getConfig().maximumBalance))
|
||||
: new IntegerArgument("amount", 1, this.manager.plugin.getConfig().maximumBalance.intValue())
|
||||
? new DoubleArgument("amount", 1)
|
||||
: new IntegerArgument("amount", 1)
|
||||
)
|
||||
.executes((sender, args) -> {
|
||||
this.handleTake(sender, args, currency);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package dev.xhyrom.lighteco.bukkit.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@UtilityClass
|
||||
public class Util {
|
||||
public double bigDecimalToDouble(final BigDecimal value) {
|
||||
double amount = value.doubleValue();
|
||||
|
||||
// Don't return bigger balance than user actually has
|
||||
if (BigDecimal.valueOf(amount).compareTo(value) > 0) {
|
||||
amount = Math.nextAfter(amount, Double.NEGATIVE_INFINITY);
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue