Add a cooldown to the queue command (configurable)

This commit is contained in:
ajgeiss0702
2023-01-11 16:04:16 -07:00
parent 1372390988
commit 5cd13c2576
4 changed files with 25 additions and 1 deletions
@@ -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<AdaptedPlayer, Long> 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"));
@@ -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();
@@ -212,6 +212,7 @@ public class QueueMain extends AjQueueAPI {
d.put("errors.wrong-version.base", "<red>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", "<red>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!");
+7 -1
View File
@@ -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