diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java index 51ee506..7882641 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java @@ -11,9 +11,13 @@ import us.ajg0702.utils.common.Messages; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class QueueCommand extends BaseCommand { + public static Map cooldowns = new ConcurrentHashMap<>(); + private final QueueMain main; public QueueCommand(QueueMain main) { @@ -58,6 +62,14 @@ public class QueueCommand extends BaseCommand { } AdaptedPlayer player = main.getPlatformMethods().senderToPlayer(sender); + long lastUse = cooldowns.getOrDefault(player, 0L); + if(System.currentTimeMillis() - lastUse < main.getConfig().getDouble("queue-command-cooldown") * 1000L) { + sender.sendMessage(main.getMessages().getComponent("errors.too-fast-queue")); + return; + } + + cooldowns.put(player, System.currentTimeMillis()); + if(args.length > 0) { if(main.getConfig().getBoolean("require-permission") && !player.hasPermission("ajqueue.queue."+args[0])) { sender.sendMessage(getMessages().getComponent("noperm")); diff --git a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java index 00bcda2..419ee99 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -12,6 +12,7 @@ import us.ajg0702.queue.api.queues.QueueServer; import us.ajg0702.queue.api.server.AdaptedServer; import us.ajg0702.queue.commands.commands.PlayerSender; import us.ajg0702.queue.commands.commands.manage.PauseQueueServer; +import us.ajg0702.queue.commands.commands.queue.QueueCommand; import us.ajg0702.queue.common.players.QueuePlayerImpl; import us.ajg0702.queue.common.utils.Debug; import us.ajg0702.utils.common.TimeUtils; @@ -195,6 +196,10 @@ public class EventHandlerImpl implements EventHandler { } } + if(main.getConfig().getBoolean("include-server-switch-in-cooldown")) { + QueueCommand.cooldowns.put(player, System.currentTimeMillis()); + } + if(!PauseQueueServer.pausedPlayers.contains(player)) { String serverName = player.getServerName(); diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java index cf1d577..b46f843 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java @@ -212,6 +212,7 @@ public class QueueMain extends AjQueueAPI { d.put("errors.wrong-version.base", "You must be on {VERSIONS} to join this server!"); d.put("errors.wrong-version.or", " or "); d.put("errors.wrong-version.comma", ", "); + d.put("errors.too-fast-queue", "You're queueing too fast!"); d.put("commands.leave-queue", "&aYou left the queue for {SERVER}!"); d.put("commands.reload", "&aConfig and messages reloaded successfully!"); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 42d98c1..b77b748 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Dont touch this number please -config-version: 34 +config-version: 35 # This is the main config for ajQueue. @@ -313,6 +313,12 @@ give-fulljoin-players-priority: 0 # not in the queue for the target server, it will add them. force-queue-server-target: true +# How long should the cooldown for queue commands be? (in seconds) +queue-command-cooldown: 15 + +# Should any server switch (including the initial join) count against the queue command cooldown? +include-server-switch-in-cooldown: false + # The minimum time between pinging the server. # If ajQueue is pinging your backend servers too often, raise this number