diff --git a/duels-api/src/main/java/me/realized/duels/api/match/Match.java b/duels-api/src/main/java/me/realized/duels/api/match/Match.java index 16a22835..40b385f1 100644 --- a/duels-api/src/main/java/me/realized/duels/api/match/Match.java +++ b/duels-api/src/main/java/me/realized/duels/api/match/Match.java @@ -57,7 +57,7 @@ public interface Match { * * @return bet Bet amount for this {@link Match} or 0 if no bet was specified. */ - int getBet(); + double getBet(); /** diff --git a/duels-api/src/main/java/me/realized/duels/api/queue/DQueue.java b/duels-api/src/main/java/me/realized/duels/api/queue/DQueue.java index 91f35ca0..2a0ad255 100644 --- a/duels-api/src/main/java/me/realized/duels/api/queue/DQueue.java +++ b/duels-api/src/main/java/me/realized/duels/api/queue/DQueue.java @@ -25,7 +25,7 @@ public interface DQueue { * * @return Bet amount for this {@link DQueue} or 0 if no bet was specified. */ - int getBet(); + double getBet(); /** @@ -50,7 +50,7 @@ public interface DQueue { * Whether or not this {@link DQueue} has been removed. * * @return True if this {@link DQueue} has been removed. False otherwise. - * @see DQueueManager#remove(Kit, int) + * @see DQueueManager#remove(Kit, double) */ boolean isRemoved(); } diff --git a/duels-api/src/main/java/me/realized/duels/api/queue/DQueueManager.java b/duels-api/src/main/java/me/realized/duels/api/queue/DQueueManager.java index 2539b361..33c9cf39 100644 --- a/duels-api/src/main/java/me/realized/duels/api/queue/DQueueManager.java +++ b/duels-api/src/main/java/me/realized/duels/api/queue/DQueueManager.java @@ -26,7 +26,7 @@ public interface DQueueManager { * @return DQueue with the given kit and bet if found, otherwise null. */ @Nullable - DQueue get(@Nullable final Kit kit, final int bet); + DQueue get(@Nullable final Kit kit, final double bet); /** @@ -48,16 +48,16 @@ public interface DQueueManager { * @return The newly created DQueue or null if a queue with given kit and bet already exists */ @Nullable - DQueue create(@Nullable final CommandSender source, @Nullable final Kit kit, final int bet); + DQueue create(@Nullable final CommandSender source, @Nullable final Kit kit, final double bet); /** - * Calls {@link #create(CommandSender, Kit, int)} with source being null. + * Calls {@link #create(CommandSender, Kit, double)} with source being null. * - * @see #create(CommandSender, Kit, int) + * @see #create(CommandSender, Kit, double) */ @Nullable - DQueue create(@Nullable final Kit kit, final int bet); + DQueue create(@Nullable final Kit kit, final double bet); /** @@ -70,16 +70,16 @@ public interface DQueueManager { * @see DQueue#isRemoved() */ @Nullable - DQueue remove(@Nullable final CommandSender source, @Nullable final Kit kit, final int bet); + DQueue remove(@Nullable final CommandSender source, @Nullable final Kit kit, final double bet); /** - * Calls {@link #remove(CommandSender, Kit, int)} with source being null. + * Calls {@link #remove(CommandSender, Kit, double)} with source being null. * - * @see #remove(CommandSender, Kit, int) + * @see #remove(CommandSender, Kit, double) */ @Nullable - DQueue remove(@Nullable final Kit kit, final int bet); + DQueue remove(@Nullable final Kit kit, final double bet); /** diff --git a/duels-api/src/main/java/me/realized/duels/api/request/Request.java b/duels-api/src/main/java/me/realized/duels/api/request/Request.java index e85dc419..feb31d51 100644 --- a/duels-api/src/main/java/me/realized/duels/api/request/Request.java +++ b/duels-api/src/main/java/me/realized/duels/api/request/Request.java @@ -60,5 +60,5 @@ public interface Request { * * @return Bet amount for this {@link Request} or 0 if not specified. */ - int getBet(); + double getBet(); } diff --git a/duels-plugin/src/main/java/me/realized/duels/arena/ArenaImpl.java b/duels-plugin/src/main/java/me/realized/duels/arena/ArenaImpl.java index f59a82bd..140fbe93 100644 --- a/duels-plugin/src/main/java/me/realized/duels/arena/ArenaImpl.java +++ b/duels-plugin/src/main/java/me/realized/duels/arena/ArenaImpl.java @@ -150,7 +150,7 @@ public boolean isAvailable() { return !isDisabled() && !isUsed() && getPosition(1) != null && getPosition(2) != null; } - public MatchImpl startMatch(final KitImpl kit, final Map> items, final int bet, final Queue source) { + public MatchImpl startMatch(final KitImpl kit, final Map> items, final double bet, final Queue source) { this.match = new MatchImpl(this, kit, items, bet, source); refreshGui(false); return match; diff --git a/duels-plugin/src/main/java/me/realized/duels/arena/MatchImpl.java b/duels-plugin/src/main/java/me/realized/duels/arena/MatchImpl.java index a2c001ad..aeab9b80 100644 --- a/duels-plugin/src/main/java/me/realized/duels/arena/MatchImpl.java +++ b/duels-plugin/src/main/java/me/realized/duels/arena/MatchImpl.java @@ -28,7 +28,7 @@ public class MatchImpl implements Match { private final KitImpl kit; private final Map> items; @Getter - private final int bet; + private final double bet; @Getter private final Queue source; @@ -38,7 +38,7 @@ public class MatchImpl implements Match { // Default value for players is false, which is set to true if player is killed in the match. private final Map players = new HashMap<>(); - MatchImpl(final ArenaImpl arena, final KitImpl kit, final Map> items, final int bet, final Queue source) { + MatchImpl(final ArenaImpl arena, final KitImpl kit, final Map> items, final double bet, final Queue source) { this.arena = arena; this.start = System.currentTimeMillis(); this.kit = kit; diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/SpectateCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/SpectateCommand.java index 97168b26..6c5898b3 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/SpectateCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/SpectateCommand.java @@ -7,6 +7,7 @@ import me.realized.duels.arena.MatchImpl; import me.realized.duels.command.BaseCommand; import me.realized.duels.spectate.SpectatorImpl; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.inventory.InventoryUtil; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -79,7 +80,7 @@ protected void execute(final CommandSender sender, final String label, final Str "opponent", arena.getOpponent(target).getName(), "kit", kit, "arena", arena.getName(), - "bet_amount", match.getBet() + "bet_amount", NumberUtil.formatDouble(match.getBet()) ); } } diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/DuelCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/DuelCommand.java index 64c6bd0c..b69c725f 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/DuelCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/DuelCommand.java @@ -160,9 +160,9 @@ protected boolean executeFirst(final CommandSender sender, final String label, f boolean sendRequest = false; if (args.length > 1) { - final int amount = NumberUtil.parseInt(args[1]).orElse(0); + final double amount = NumberUtil.parseDouble(args[1]).orElse(0.0); - if (amount > 0 && config.isMoneyBettingEnabled()) { + if (amount >= config.getMoneyBettingMinimumBetAmount() && config.isMoneyBettingEnabled()) { if (config.isMoneyBettingUsePermission() && !player.hasPermission(Permissions.MONEY_BETTING) && !player.hasPermission(Permissions.SETTING_ALL)) { lang.sendMessage(player, "ERROR.no-permission", "permission", Permissions.MONEY_BETTING); return true; @@ -173,6 +173,11 @@ protected boolean executeFirst(final CommandSender sender, final String label, f return true; } + if (amount > config.getMoneyBettingMaximumBetAmount()) { + lang.sendMessage(sender, "ERROR.command.exceeding-maximum-betting-amount"); + return true; + } + if (!vault.getEconomy().has(player, amount)) { lang.sendMessage(sender, "ERROR.command.not-enough-money"); return true; diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/subcommands/AcceptCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/subcommands/AcceptCommand.java index 8a3a889b..9a0dbaee 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/subcommands/AcceptCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duel/subcommands/AcceptCommand.java @@ -9,6 +9,7 @@ import me.realized.duels.hook.hooks.worldguard.WorldGuardHook; import me.realized.duels.request.RequestImpl; import me.realized.duels.setting.Settings; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.inventory.InventoryUtil; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -107,9 +108,9 @@ protected void execute(final CommandSender sender, final String label, final Str final double bet = settings.getBet(); final String itemBetting = settings.isItemBetting() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"); lang.sendMessage(player, "COMMAND.duel.request.accept.receiver", - "name", target.getName(), "kit", kit, "arena", arena, "bet_amount", bet, "item_betting", itemBetting); + "name", target.getName(), "kit", kit, "arena", arena, "bet_amount", NumberUtil.formatDouble(bet), "item_betting", itemBetting); lang.sendMessage(target, "COMMAND.duel.request.accept.sender", - "name", player.getName(), "kit", kit, "arena", arena, "bet_amount", bet, "item_betting", itemBetting); + "name", player.getName(), "kit", kit, "arena", arena, "bet_amount", NumberUtil.formatDouble(bet), "item_betting", itemBetting); if (settings.isItemBetting()) { settings.setBaseLoc(player); diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/AddsignCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/AddsignCommand.java index 257c9000..f152917d 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/AddsignCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/AddsignCommand.java @@ -31,7 +31,7 @@ protected void execute(final CommandSender sender, final String label, final Str return; } - final int bet = NumberUtil.parseInt(args[1]).orElse(0); + final double bet = NumberUtil.parseDouble(args[1]).orElse(0.0); KitImpl kit = null; if (!args[2].equals("-")) { @@ -48,7 +48,7 @@ protected void execute(final CommandSender sender, final String label, final Str final Queue queue = queueManager.get(kit, bet); if (queue == null) { - lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", bet, "kit", kitName); + lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", NumberUtil.formatDouble(bet), "kit", kitName); return; } @@ -58,7 +58,7 @@ protected void execute(final CommandSender sender, final String label, final Str } final Location location = sign.getLocation(); - lang.sendMessage(sender, "COMMAND.duels.add-sign", "location", StringUtil.parse(location), "kit", kitName, "bet_amount", bet); + lang.sendMessage(sender, "COMMAND.duels.add-sign", "location", StringUtil.parse(location), "kit", kitName, "bet_amount", NumberUtil.formatDouble(bet)); } @Override diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/CreatequeueCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/CreatequeueCommand.java index 8428c83a..5bff840f 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/CreatequeueCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/CreatequeueCommand.java @@ -18,7 +18,7 @@ public CreatequeueCommand(final DuelsPlugin plugin) { @Override protected void execute(final CommandSender sender, final String label, final String[] args) { - final int bet = NumberUtil.parseInt(args[1]).orElse(0); + final double bet = NumberUtil.parseDouble(args[1]).orElse(0.0); KitImpl kit = null; if (!args[2].equals("-")) { @@ -34,11 +34,11 @@ protected void execute(final CommandSender sender, final String label, final Str final String kitName = kit != null ? kit.getName() : lang.getMessage("GENERAL.none"); if (queueManager.create(sender, kit, bet) == null) { - lang.sendMessage(sender, "ERROR.queue.already-exists", "kit", kitName, "bet_amount", bet); + lang.sendMessage(sender, "ERROR.queue.already-exists", "kit", kitName, "bet_amount", NumberUtil.formatDouble(bet)); return; } - lang.sendMessage(sender, "COMMAND.duels.create-queue", "kit", kitName, "bet_amount", bet); + lang.sendMessage(sender, "COMMAND.duels.create-queue", "kit", kitName, "bet_amount", NumberUtil.formatDouble(bet)); } @Override diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletequeueCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletequeueCommand.java index a5befca8..7496abfa 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletequeueCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletequeueCommand.java @@ -18,7 +18,7 @@ public DeletequeueCommand(final DuelsPlugin plugin) { @Override protected void execute(final CommandSender sender, final String label, final String[] args) { - final int bet = NumberUtil.parseInt(args[1]).orElse(0); + final double bet = NumberUtil.parseDouble(args[1]).orElse(0.0); KitImpl kit = null; if (!args[2].equals("-")) { @@ -34,11 +34,11 @@ protected void execute(final CommandSender sender, final String label, final Str final String kitName = kit != null ? kit.getName() : lang.getMessage("GENERAL.none"); if (queueManager.remove(sender, kit, bet) == null) { - lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", bet, "kit", kitName); + lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", NumberUtil.formatDouble(bet), "kit", kitName); return; } - lang.sendMessage(sender, "COMMAND.duels.delete-queue", "kit", kitName, "bet_amount", bet); + lang.sendMessage(sender, "COMMAND.duels.delete-queue", "kit", kitName, "bet_amount", NumberUtil.formatDouble(bet)); } @Override diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletesignCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletesignCommand.java index 9af41205..aee0a18d 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletesignCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/duels/subcommands/DeletesignCommand.java @@ -6,6 +6,7 @@ import me.realized.duels.queue.Queue; import me.realized.duels.queue.sign.QueueSignImpl; import me.realized.duels.util.BlockUtil; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.StringUtil; import org.bukkit.Location; import org.bukkit.Material; @@ -43,6 +44,6 @@ protected void execute(final CommandSender sender, final String label, final Str final Queue queue = queueSign.getQueue(); final Kit kit = queue.getKit(); final String kitName = kit != null ? kit.getName() : lang.getMessage("GENERAL.none"); - lang.sendMessage(sender, "COMMAND.duels.del-sign", "location", StringUtil.parse(location), "kit", kitName, "bet_amount", queue.getBet()); + lang.sendMessage(sender, "COMMAND.duels.del-sign", "location", StringUtil.parse(location), "kit", kitName, "bet_amount", NumberUtil.formatDouble(queue.getBet())); } } diff --git a/duels-plugin/src/main/java/me/realized/duels/command/commands/queue/subcommands/JoinCommand.java b/duels-plugin/src/main/java/me/realized/duels/command/commands/queue/subcommands/JoinCommand.java index 5d99079d..9ef2273a 100644 --- a/duels-plugin/src/main/java/me/realized/duels/command/commands/queue/subcommands/JoinCommand.java +++ b/duels-plugin/src/main/java/me/realized/duels/command/commands/queue/subcommands/JoinCommand.java @@ -35,11 +35,11 @@ protected void execute(final CommandSender sender, final String label, final Str } final String kitName = kit != null ? kit.getName() : lang.getMessage("GENERAL.none"); - final int bet = args.length > 2 ? NumberUtil.parseInt(args[args.length - 1]).orElse(0) : 0; + final double bet = args.length > 2 ? NumberUtil.parseDouble(args[args.length - 1]).orElse(0) : 0; final Queue queue = args[1].equals("-r") ? queueManager.randomQueue() : queueManager.get(kit, bet); if (queue == null) { - lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", bet, "kit", kitName); + lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", NumberUtil.formatDouble(bet), "kit", kitName); return; } diff --git a/duels-plugin/src/main/java/me/realized/duels/config/Config.java b/duels-plugin/src/main/java/me/realized/duels/config/Config.java index d9ab207e..fe8bbc4a 100644 --- a/duels-plugin/src/main/java/me/realized/duels/config/Config.java +++ b/duels-plugin/src/main/java/me/realized/duels/config/Config.java @@ -89,6 +89,10 @@ public class Config extends AbstractConfiguration { @Getter private boolean moneyBettingUsePermission; @Getter + private double moneyBettingMinimumBetAmount; + @Getter + private double moneyBettingMaximumBetAmount; + @Getter private int expiration; @Getter @@ -297,6 +301,8 @@ protected void loadValues(FileConfiguration configuration) throws Exception { itemBettingUsePermission = configuration.getBoolean("request.item-betting.use-permission", false); moneyBettingEnabled = configuration.getBoolean("request.money-betting.enabled", true); moneyBettingUsePermission = configuration.getBoolean("request.money-betting.use-permission", false); + moneyBettingMinimumBetAmount = configuration.getDouble("request.money-betting.minimum-bet-amount", 0.001); + moneyBettingMaximumBetAmount = configuration.getDouble("request.money-betting.maximum-bet-amount", 10000000000.0); expiration = Math.max(configuration.getInt("request.expiration", 30), 0); maxDuration = configuration.getInt("duel.match.max-duration", -1); diff --git a/duels-plugin/src/main/java/me/realized/duels/data/QueueData.java b/duels-plugin/src/main/java/me/realized/duels/data/QueueData.java index 6c80c9b4..a2a3f3d0 100644 --- a/duels-plugin/src/main/java/me/realized/duels/data/QueueData.java +++ b/duels-plugin/src/main/java/me/realized/duels/data/QueueData.java @@ -6,7 +6,7 @@ public class QueueData { private String kit; - private int bet; + private double bet; private QueueData() {} diff --git a/duels-plugin/src/main/java/me/realized/duels/data/QueueSignData.java b/duels-plugin/src/main/java/me/realized/duels/data/QueueSignData.java index 4cd6419f..d713dbbd 100644 --- a/duels-plugin/src/main/java/me/realized/duels/data/QueueSignData.java +++ b/duels-plugin/src/main/java/me/realized/duels/data/QueueSignData.java @@ -4,6 +4,7 @@ import me.realized.duels.kit.KitImpl; import me.realized.duels.queue.Queue; import me.realized.duels.queue.sign.QueueSignImpl; +import me.realized.duels.util.NumberUtil; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -12,7 +13,7 @@ public class QueueSignData { private LocationData location; private String kit; - private int bet; + private double bet; private QueueSignData() {} @@ -45,6 +46,9 @@ public QueueSignImpl toQueueSign(final DuelsPlugin plugin) { queue = plugin.getQueueManager().get(kit, bet); } - return new QueueSignImpl(location, plugin.getLang().getMessage("SIGN.format", "kit", this.kit != null ? this.kit : plugin.getLang().getMessage("GENERAL.none"), "bet_amount", bet), queue); + return new QueueSignImpl(location, plugin.getLang().getMessage("SIGN.format", + "kit", this.kit != null ? this.kit : plugin.getLang().getMessage("GENERAL.none"), + "bet_amount", NumberUtil.formatDouble(bet) + ), queue); } } \ No newline at end of file diff --git a/duels-plugin/src/main/java/me/realized/duels/duel/DuelManager.java b/duels-plugin/src/main/java/me/realized/duels/duel/DuelManager.java index 378ab220..d444cc35 100644 --- a/duels-plugin/src/main/java/me/realized/duels/duel/DuelManager.java +++ b/duels-plugin/src/main/java/me/realized/duels/duel/DuelManager.java @@ -241,11 +241,11 @@ private void handleWin(final Player player, final Player opponent, final ArenaIm final String opponentName = opponent != null ? opponent.getName() : lang.getMessage("GENERAL.none"); if (vault != null && match.getBet() > 0) { - final int amount = match.getBet() * 2; + final double amount = match.getBet() * 2; vault.add(amount, player); - lang.sendMessage(player, "DUEL.reward.money.message", "name", opponentName, "money", amount); + lang.sendMessage(player, "DUEL.reward.money.message", "name", opponentName, "money", NumberUtil.formatDouble(amount)); - final String title = lang.getMessage("DUEL.reward.money.title", "name", opponentName, "money", amount); + final String title = lang.getMessage("DUEL.reward.money.title", "name", opponentName, "money", NumberUtil.formatDouble(amount)); if (title != null) { Titles.send(player, title, null, 0, 20, 50); @@ -338,11 +338,12 @@ public void startMatch(final Player first, final Player second, final Settings s return; } - final int bet = settings.getBet(); + final double bet = settings.getBet(); if (bet > 0 && vault != null && vault.getEconomy() != null) { if (!vault.has(bet, first, second)) { - lang.sendMessage(Arrays.asList(first, second), "DUEL.start-failure.not-enough-money", "bet_amount", bet); + lang.sendMessage(Arrays.asList(first, second), "DUEL.start-failure.not-enough-money", + "bet_amount", NumberUtil.formatDouble(bet)); refundItems(items, first, second); return; } @@ -591,7 +592,7 @@ public void on(final PlayerDeathEvent event) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command .replace("%winner%", winner.getName()).replace("%loser%", player.getName()) .replace("%kit%", kitName).replace("%arena%", arena.getName()) - .replace("%bet_amount%", String.valueOf(match.getBet())) + .replace("%bet_amount%", NumberUtil.formatDouble(match.getBet())) ); } } catch (Exception ex) { diff --git a/duels-plugin/src/main/java/me/realized/duels/gui/betting/buttons/DetailsButton.java b/duels-plugin/src/main/java/me/realized/duels/gui/betting/buttons/DetailsButton.java index 6db7ea31..f58dadf2 100644 --- a/duels-plugin/src/main/java/me/realized/duels/gui/betting/buttons/DetailsButton.java +++ b/duels-plugin/src/main/java/me/realized/duels/gui/betting/buttons/DetailsButton.java @@ -3,6 +3,7 @@ import me.realized.duels.DuelsPlugin; import me.realized.duels.gui.BaseButton; import me.realized.duels.setting.Settings; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.compat.Items; import me.realized.duels.util.inventory.ItemBuilder; import org.bukkit.entity.Player; @@ -25,7 +26,7 @@ public void update(final Player player) { final String lore = lang.getMessage("GUI.item-betting.buttons.details.lore", "kit", settings.getKit() != null ? settings.getKit().getName() : lang.getMessage("GENERAL.not-selected"), "arena", settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random"), - "bet_amount", settings.getBet() + "bet_amount", NumberUtil.formatDouble(settings.getBet()) ); setLore(lore.split("\n")); } diff --git a/duels-plugin/src/main/java/me/realized/duels/gui/settings/buttons/RequestDetailsButton.java b/duels-plugin/src/main/java/me/realized/duels/gui/settings/buttons/RequestDetailsButton.java index 7a90fd22..6be7fd27 100644 --- a/duels-plugin/src/main/java/me/realized/duels/gui/settings/buttons/RequestDetailsButton.java +++ b/duels-plugin/src/main/java/me/realized/duels/gui/settings/buttons/RequestDetailsButton.java @@ -3,6 +3,7 @@ import me.realized.duels.DuelsPlugin; import me.realized.duels.gui.BaseButton; import me.realized.duels.setting.Settings; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.compat.Items; import me.realized.duels.util.inventory.ItemBuilder; import org.bukkit.Bukkit; @@ -32,7 +33,7 @@ public void update(final Player player) { "own_inventory", settings.isOwnInventory() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"), "arena", settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random"), "item_betting", settings.isItemBetting() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"), - "bet_amount", settings.getBet() + "bet_amount", NumberUtil.formatDouble(settings.getBet()) ); setLore(lore.split("\n")); } diff --git a/duels-plugin/src/main/java/me/realized/duels/hook/hooks/VaultHook.java b/duels-plugin/src/main/java/me/realized/duels/hook/hooks/VaultHook.java index 1635ac06..4648fc1a 100644 --- a/duels-plugin/src/main/java/me/realized/duels/hook/hooks/VaultHook.java +++ b/duels-plugin/src/main/java/me/realized/duels/hook/hooks/VaultHook.java @@ -31,6 +31,7 @@ public VaultHook(final DuelsPlugin plugin) { Log.info("Using Economy Provider: " + economy.getClass().getName()); } + @Deprecated public boolean has(final int amount, final Player... players) { if (economy == null) { return false; @@ -45,15 +46,55 @@ public boolean has(final int amount, final Player... players) { return true; } + @Deprecated public void add(final int amount, final Player... players) { if (economy != null) { Arrays.stream(players).forEach(player -> economy.depositPlayer(player, amount)); } } + @Deprecated public void remove(final int amount, final Player... players) { if (economy != null) { Arrays.stream(players).forEach(player -> economy.withdrawPlayer(player, amount)); } } + + public boolean has(final double amount, final Player... players) { + if (economy == null) { + return false; + } + + boolean result = true; + + for (final Player player : players) { + if (economy.has(player, amount)) { + continue; + } + result = false; + break; + } + + return result; + } + + public void add(final double amount, final Player... players) { + if (economy == null) { + return; + } + + for (Player player : players) { + economy.depositPlayer(player, amount); + } + } + + public void remove(final double amount, final Player... players) { + if (economy == null) { + return; + } + + for (Player player : players) { + economy.withdrawPlayer(player, amount); + } + } } diff --git a/duels-plugin/src/main/java/me/realized/duels/queue/Queue.java b/duels-plugin/src/main/java/me/realized/duels/queue/Queue.java index b5cf3201..e9a87005 100644 --- a/duels-plugin/src/main/java/me/realized/duels/queue/Queue.java +++ b/duels-plugin/src/main/java/me/realized/duels/queue/Queue.java @@ -13,6 +13,7 @@ import me.realized.duels.api.kit.Kit; import me.realized.duels.api.queue.DQueue; import me.realized.duels.gui.BaseButton; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.inventory.ItemBuilder; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -23,20 +24,20 @@ public class Queue extends BaseButton implements DQueue { @Getter private final Kit kit; @Getter - private final int bet; + private final double bet; @Getter private final List players = new LinkedList<>(); @Getter @Setter(value = AccessLevel.PACKAGE) private boolean removed; - public Queue(final DuelsPlugin plugin, final Kit kit, final int bet) { + public Queue(final DuelsPlugin plugin, final Kit kit, final double bet) { super(plugin, ItemBuilder .of((plugin.getConfiguration().isInheritKitItemType() && kit != null) ? kit.getDisplayed().clone() : ItemBuilder.of(Material.DIAMOND_SWORD).build()) .name(plugin.getLang().getMessage("GUI.queues.buttons.queue.name", - "kit", kit != null ? kit.getName() : plugin.getLang().getMessage("GENERAL.none"), "bet_amount", bet, "in_queue", 0, "in_match", 0)) + "kit", kit != null ? kit.getName() : plugin.getLang().getMessage("GENERAL.none"), "bet_amount", NumberUtil.formatDouble(bet), "in_queue", 0, "in_match", 0)) .lore(plugin.getLang().getMessage("GUI.queues.buttons.queue.lore", - "kit", kit != null ? kit.getName() : plugin.getLang().getMessage("GENERAL.none"), "bet_amount", bet, "in_queue", 0, "in_match", 0).split("\n")) + "kit", kit != null ? kit.getName() : plugin.getLang().getMessage("GENERAL.none"), "bet_amount", NumberUtil.formatDouble(bet), "in_queue", 0, "in_match", 0).split("\n")) .build()); this.kit = kit; this.bet = bet; @@ -86,9 +87,9 @@ public void update() { int inQueue = players.size(); long inMatch = getPlayersInMatch(); setDisplayName(lang.getMessage("GUI.queues.buttons.queue.name", - "kit", kit != null ? kit.getName() : lang.getMessage("GENERAL.none"), "bet_amount", bet, "in_queue", inQueue, "in_match", inMatch)); + "kit", kit != null ? kit.getName() : lang.getMessage("GENERAL.none"), "bet_amount", NumberUtil.formatDouble(bet), "in_queue", inQueue, "in_match", inMatch)); setLore(lang.getMessage("GUI.queues.buttons.queue.lore", - "kit", kit != null ? kit.getName() : lang.getMessage("GENERAL.none"), "bet_amount", bet, "in_queue", inQueue, "in_match", inMatch).split("\n")); + "kit", kit != null ? kit.getName() : lang.getMessage("GENERAL.none"), "bet_amount", NumberUtil.formatDouble(bet), "in_queue", inQueue, "in_match", inMatch).split("\n")); } @Override diff --git a/duels-plugin/src/main/java/me/realized/duels/queue/QueueManager.java b/duels-plugin/src/main/java/me/realized/duels/queue/QueueManager.java index 37fd7518..77778dcf 100644 --- a/duels-plugin/src/main/java/me/realized/duels/queue/QueueManager.java +++ b/duels-plugin/src/main/java/me/realized/duels/queue/QueueManager.java @@ -187,8 +187,8 @@ public void handleLoad() throws IOException { setting.getCache().put(other.getUniqueId(), opponent.getInfo()); final String kit = queue.getKit() != null ? queue.getKit().getName() : lang.getMessage("GENERAL.none"); - lang.sendMessage(player, "QUEUE.found-opponent", "name", other.getName(), "kit", kit, "bet_amount", queue.getBet()); - lang.sendMessage(other, "QUEUE.found-opponent", "name", player.getName(), "kit", kit, "bet_amount", queue.getBet()); + lang.sendMessage(player, "QUEUE.found-opponent", "name", other.getName(), "kit", kit, "bet_amount", NumberUtil.formatDouble(queue.getBet())); + lang.sendMessage(other, "QUEUE.found-opponent", "name", player.getName(), "kit", kit, "bet_amount", NumberUtil.formatDouble(queue.getBet())); duelManager.startMatch(player, other, setting, null, queue); break; } @@ -233,7 +233,7 @@ private void saveQueues() { @Nullable @Override - public Queue get(@Nullable final Kit kit, final int bet) { + public Queue get(@Nullable final Kit kit, final double bet) { return queues.stream().filter(queue -> Objects.equals(kit, queue.getKit()) && queue.getBet() == bet).findFirst().orElse(null); } @@ -251,7 +251,7 @@ public Queue randomQueue() { @Nullable @Override - public Queue create(@Nullable final CommandSender source, @Nullable final Kit kit, final int bet) { + public Queue create(@Nullable final CommandSender source, @Nullable final Kit kit, final double bet) { final Queue queue = new Queue(plugin, kit, bet); if (queues.contains(queue)) { @@ -269,19 +269,19 @@ public Queue create(@Nullable final CommandSender source, @Nullable final Kit ki @Nullable @Override - public Queue create(@Nullable final Kit kit, final int bet) { + public Queue create(@Nullable final Kit kit, final double bet) { return create(null, kit, bet); } @Nullable @Override - public Queue remove(@Nullable final CommandSender source, @Nullable final Kit kit, final int bet) { + public Queue remove(@Nullable final CommandSender source, @Nullable final Kit kit, final double bet) { return remove(source, get(kit, bet)); } @Nullable @Override - public Queue remove(@Nullable final Kit kit, final int bet) { + public Queue remove(@Nullable final Kit kit, final double bet) { return remove(null, kit, bet); } @@ -374,7 +374,7 @@ public boolean queue(final Player player, final Queue queue) { } if (queue.getBet() > 0 && vault != null && !vault.has(queue.getBet(), player)) { - lang.sendMessage(player, "ERROR.queue.not-enough-money", "bet_amount", queue.getBet()); + lang.sendMessage(player, "ERROR.queue.not-enough-money", "bet_amount", NumberUtil.formatDouble(queue.getBet())); return false; } @@ -388,7 +388,7 @@ public boolean queue(final Player player, final Queue queue) { queue.addPlayer(new QueueEntry(player, player.getLocation().clone(), duelzone)); final String kit = queue.getKit() != null ? queue.getKit().getName() : lang.getMessage("GENERAL.none"); - lang.sendMessage(player, "QUEUE.add", "kit", kit, "bet_amount", queue.getBet()); + lang.sendMessage(player, "QUEUE.add", "kit", kit, "bet_amount", NumberUtil.formatDouble(queue.getBet())); return true; } diff --git a/duels-plugin/src/main/java/me/realized/duels/queue/sign/QueueSignManagerImpl.java b/duels-plugin/src/main/java/me/realized/duels/queue/sign/QueueSignManagerImpl.java index 354a06e5..27436d96 100644 --- a/duels-plugin/src/main/java/me/realized/duels/queue/sign/QueueSignManagerImpl.java +++ b/duels-plugin/src/main/java/me/realized/duels/queue/sign/QueueSignManagerImpl.java @@ -29,6 +29,7 @@ import me.realized.duels.queue.QueueManager; import me.realized.duels.util.Loadable; import me.realized.duels.util.Log; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.io.FileUtil; import me.realized.duels.util.json.JsonUtil; import org.bukkit.Bukkit; @@ -137,7 +138,10 @@ public boolean create(final Player creator, final Location location, final Queue final QueueSignImpl created; final String kitName = queue.getKit() != null ? queue.getKit().getName() : lang.getMessage("GENERAL.none"); - signs.put(location, created = new QueueSignImpl(location, lang.getMessage("SIGN.format", "kit", kitName, "bet_amount", queue.getBet()), queue)); + signs.put(location, created = new QueueSignImpl(location, lang.getMessage("SIGN.format", + "kit", kitName, + "bet_amount", NumberUtil.formatDouble(queue.getBet()) + ), queue)); signs.values().stream().filter(sign -> sign.equals(created)).forEach(QueueSignImpl::update); saveQueueSigns(); diff --git a/duels-plugin/src/main/java/me/realized/duels/request/RequestImpl.java b/duels-plugin/src/main/java/me/realized/duels/request/RequestImpl.java index 10b7580c..60c98bcd 100644 --- a/duels-plugin/src/main/java/me/realized/duels/request/RequestImpl.java +++ b/duels-plugin/src/main/java/me/realized/duels/request/RequestImpl.java @@ -45,7 +45,7 @@ public boolean canBetItems() { } @Override - public int getBet() { + public double getBet() { return settings.getBet(); } } diff --git a/duels-plugin/src/main/java/me/realized/duels/request/RequestManager.java b/duels-plugin/src/main/java/me/realized/duels/request/RequestManager.java index 1e8f05af..5a50c407 100644 --- a/duels-plugin/src/main/java/me/realized/duels/request/RequestManager.java +++ b/duels-plugin/src/main/java/me/realized/duels/request/RequestManager.java @@ -9,6 +9,7 @@ import me.realized.duels.config.Lang; import me.realized.duels.setting.Settings; import me.realized.duels.util.Loadable; +import me.realized.duels.util.NumberUtil; import me.realized.duels.util.TextBuilder; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent.Action; @@ -62,13 +63,13 @@ public void send(final Player sender, final Player target, final Settings settin final String kit = settings.getKit() != null ? settings.getKit().getName() : lang.getMessage("GENERAL.not-selected"); final String ownInventory = settings.isOwnInventory() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"); final String arena = settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random"); - final int betAmount = settings.getBet(); + final double bet = settings.getBet(); final String itemBetting = settings.isItemBetting() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"); lang.sendMessage(sender, "COMMAND.duel.request.send.sender", - "name", target.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "bet_amount", betAmount, "item_betting", itemBetting); + "name", target.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "bet_amount", NumberUtil.formatDouble(bet), "item_betting", itemBetting); lang.sendMessage(target, "COMMAND.duel.request.send.receiver", - "name", sender.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "bet_amount", betAmount, "item_betting", itemBetting); + "name", sender.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "bet_amount", NumberUtil.formatDouble(bet), "item_betting", itemBetting); final String path = "COMMAND.duel.request.send.clickable-text."; diff --git a/duels-plugin/src/main/java/me/realized/duels/setting/Settings.java b/duels-plugin/src/main/java/me/realized/duels/setting/Settings.java index 6fbaed0e..9c4d6ee4 100644 --- a/duels-plugin/src/main/java/me/realized/duels/setting/Settings.java +++ b/duels-plugin/src/main/java/me/realized/duels/setting/Settings.java @@ -26,7 +26,7 @@ public class Settings { private ArenaImpl arena; @Getter @Setter - private int bet; + private double bet; @Getter @Setter private boolean itemBetting; diff --git a/duels-plugin/src/main/java/me/realized/duels/util/NumberUtil.java b/duels-plugin/src/main/java/me/realized/duels/util/NumberUtil.java index 833fa921..9b2b6be6 100644 --- a/duels-plugin/src/main/java/me/realized/duels/util/NumberUtil.java +++ b/duels-plugin/src/main/java/me/realized/duels/util/NumberUtil.java @@ -1,5 +1,6 @@ package me.realized.duels.util; +import java.util.OptionalDouble; import java.util.OptionalInt; public final class NumberUtil { @@ -68,6 +69,33 @@ public static OptionalInt parseInt(final String s) { return OptionalInt.of(negative ? result : -result); } + /** + * Parses with the same behavior as {@link NumberUtil#parseInt(String)} but then with a double. + * @param string the String to parse + * @return an optional double + */ + public static OptionalDouble parseDouble(final String string) { + if (string == null) { + return OptionalDouble.empty(); + } + + try { + return OptionalDouble.of(Double.parseDouble(string)); + } catch (NumberFormatException e) { + return OptionalDouble.empty(); + } + } + + /** + * Formats a double to a human friendly number + * @param value double to format + * @return the formatted double as a String + */ + public static String formatDouble(final double value) { + return String.format("%,.2f", value); + } + + public static int getChange(final int k, final int winnerRating, final int loserRating) { final double wr = r(winnerRating); final double lr = r(loserRating); diff --git a/duels-plugin/src/main/resources/config.yml b/duels-plugin/src/main/resources/config.yml index 0226a285..6aaaa59b 100644 --- a/duels-plugin/src/main/resources/config.yml +++ b/duels-plugin/src/main/resources/config.yml @@ -154,6 +154,14 @@ request: # default: false use-permission: false + # The minimum acceptable amount to be used for betting. + # default: 0.001 + minimum-bet-amount: 0.001 + + # The maximum acceptable amount to be used for betting. + # default: 10000000000 (10b) + maximum-bet-amount: 10000000000 + # Request expiration, in seconds. # default: 30 expiration: 30 diff --git a/duels-plugin/src/main/resources/lang.yml b/duels-plugin/src/main/resources/lang.yml index 1576df86..2744a622 100644 --- a/duels-plugin/src/main/resources/lang.yml +++ b/duels-plugin/src/main/resources/lang.yml @@ -88,6 +88,7 @@ ERROR: sound: not-found: '{PREFIX} &cNo sound exists with the name ''%name%''.' command: + exceeding-maximum-betting-amount: '{PREFIX} &cThe chosen betting amount is too high, as it exceeds the maximum amount.' invalid-sub-command: '{PREFIX} &c''%argument%'' is not a valid sub command. Please type ''/%command%'' for help.' invalid-option: '{PREFIX} &c''%option%'' is not a valid option. Available options are: %available_options%' invalid-action: '{PREFIX} &c''%action%'' is not a valid action. Available actions are: %available_actions%'