From 0a2db4f09a0f6f80b8e13f4caa4bf8a8601b2099 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 9 Jan 2023 15:23:04 -0700 Subject: [PATCH 01/10] Fix a semi-rare error when a server is offline on bungeecord --- .../queue/platforms/bungeecord/server/BungeeServer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java index 777a12f..5f0572f 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java @@ -2,6 +2,7 @@ package us.ajg0702.queue.platforms.bungeecord.server; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.jetbrains.annotations.Nullable; import us.ajg0702.queue.api.AjQueueAPI; import us.ajg0702.queue.api.players.AdaptedPlayer; import us.ajg0702.queue.api.server.AdaptedServer; @@ -51,7 +52,7 @@ public class BungeeServer implements AdaptedServer { if(debug) logger.info("[pinger] [" + getName() + "] sending ping"); handle.ping((pp, error) -> { - if(error != null) { + if(error != null || pp == null) { markOffline(debug, logger, future, sent, error); } @@ -71,7 +72,7 @@ public class BungeeServer implements AdaptedServer { return future; } - private void markOffline(boolean debug, QueueLogger logger, CompletableFuture future, long sent, Throwable e) { + private void markOffline(boolean debug, QueueLogger logger, CompletableFuture future, long sent, @Nullable Throwable e) { long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime(); offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE); From 0f6f8a423063fff08f58e127d1e50efac314746c Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 9 Jan 2023 17:43:42 -0700 Subject: [PATCH 02/10] Catch null player in spigot-side command --- spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java b/spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java index acaa951..7acad6d 100644 --- a/spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java +++ b/spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java @@ -53,10 +53,15 @@ public class Commands implements CommandExecutor { player = tply; srvname = args[1]; } + + if(player == null) { + sender.sendMessage("I need to know what player to send!"); + return true; + } + if(pl.getAConfig().getBoolean("send-queue-commands-in-batches")) { pl.queuebatch.put(player, srvname); } else { - assert player != null; pl.sendMessage(player, "queue", srvname); } From c4983ca5ff53797fd95af99201eb66a56dad0820 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 9 Jan 2023 18:08:55 -0700 Subject: [PATCH 03/10] Will no longer auto-complete servers the player doesn't have permission to queue for --- .../ajg0702/queue/commands/commands/queue/QueueCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 0677fb4..51ee506 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 @@ -79,7 +79,11 @@ public class QueueCommand extends BaseCommand { return new ArrayList<>(); } if(args.length == 1) { - return filterCompletion(main.getQueueManager().getServerNames(), args[0]); + List servers = filterCompletion(main.getQueueManager().getServerNames(), args[0]); + if(main.getConfig().getBoolean("require-permission")) { + servers.removeIf(s -> !sender.hasPermission("ajqueue.queue." + s)); + } + return servers; } return new ArrayList<>(); } From 555ef21192f5f46091ee08446592ca840d6cf4b1 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 09:12:58 -0700 Subject: [PATCH 04/10] Really fix the semi-rare error when a server is offline on bungeecord --- .../queue/platforms/bungeecord/server/BungeeServer.java | 1 + .../queue/platforms/bungeecord/server/BungeeServerPing.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java index 5f0572f..c414a32 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServer.java @@ -54,6 +54,7 @@ public class BungeeServer implements AdaptedServer { handle.ping((pp, error) -> { if(error != null || pp == null) { markOffline(debug, logger, future, sent, error); + return; } offlineTime = 0; diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServerPing.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServerPing.java index cc1ff7e..6c476ba 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServerPing.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/server/BungeeServerPing.java @@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.chat.BaseComponent; +import org.jetbrains.annotations.NotNull; import us.ajg0702.queue.api.server.AdaptedServerPing; public class BungeeServerPing implements AdaptedServerPing { @@ -11,7 +12,7 @@ public class BungeeServerPing implements AdaptedServerPing { final ServerPing handle; private final long sent; - public BungeeServerPing(ServerPing handle, long sent) { + public BungeeServerPing(@NotNull ServerPing handle, long sent) { this.handle = handle; this.sent = sent; } From 137239098889874e563aece8757674eb23b1cda0 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 10:04:14 -0700 Subject: [PATCH 05/10] Added /ajq pausequeueserver command, which will temporarily not queue you when you are in queue-servers --- .../queue/api/commands/ICommandSender.java | 7 ++ .../queue/commands/commands/PlayerSender.java | 7 ++ .../commands/manage/ManageCommand.java | 1 + .../commands/manage/PauseQueueServer.java | 81 +++++++++++++++++++ .../queue/common/EventHandlerImpl.java | 21 ++--- .../us/ajg0702/queue/common/QueueMain.java | 3 + .../queue/common/QueueManagerImpl.java | 11 +++ .../bungeecord/commands/BungeeSender.java | 8 ++ .../bungeecord/players/BungeePlayer.java | 14 ++++ .../velocity/commands/VelocitySender.java | 9 +++ .../velocity/players/VelocityPlayer.java | 14 ++++ 11 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/PauseQueueServer.java diff --git a/api/src/main/java/us/ajg0702/queue/api/commands/ICommandSender.java b/api/src/main/java/us/ajg0702/queue/api/commands/ICommandSender.java index 041aa1d..022ba8a 100644 --- a/api/src/main/java/us/ajg0702/queue/api/commands/ICommandSender.java +++ b/api/src/main/java/us/ajg0702/queue/api/commands/ICommandSender.java @@ -3,8 +3,15 @@ package us.ajg0702.queue.api.commands; import net.kyori.adventure.audience.Audience; import us.ajg0702.queue.api.util.Handle; +import java.util.UUID; + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public interface ICommandSender extends Handle, Audience { boolean hasPermission(String permission); boolean isPlayer(); + + /** + * @throws IllegalStateException if the sender is not a player + */ + UUID getUniqueId() throws IllegalStateException; } diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java b/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java index 57da37c..d640008 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java @@ -3,6 +3,8 @@ package us.ajg0702.queue.commands.commands; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.players.AdaptedPlayer; +import java.util.UUID; + public class PlayerSender implements ICommandSender { final AdaptedPlayer handle; @@ -21,6 +23,11 @@ public class PlayerSender implements ICommandSender { return true; } + @Override + public UUID getUniqueId() throws IllegalStateException { + return handle.getUniqueId(); + } + @Override public AdaptedPlayer getHandle() { return handle; diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java index 586adce..fddb210 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java @@ -37,6 +37,7 @@ public class ManageCommand extends BaseCommand { addSubCommand(new Update(main)); addSubCommand(new Kick(main)); addSubCommand(new KickAll(main)); + addSubCommand(new PauseQueueServer(main)); } diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PauseQueueServer.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PauseQueueServer.java new file mode 100644 index 0000000..0a416e2 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PauseQueueServer.java @@ -0,0 +1,81 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.commands.ISubCommand; +import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.queue.common.utils.Debug; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +public class PauseQueueServer extends SubCommand { + + public static final List pausedPlayers = new CopyOnWriteArrayList<>(); + + final QueueMain main; + public PauseQueueServer(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "pausequeueserver"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of("pauseqs"); + } + + @Override + public ImmutableList getSubCommands() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.manage.pausequeueserver"; + } + + @Override + public boolean showInTabComplete() { + return true; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + + if(!sender.isPlayer()) { + sender.sendMessage(getMessages().getComponent("errors.player-only")); + return; + } + + AdaptedPlayer player = main.getPlatformMethods().getPlayer(sender.getUniqueId()); + if(pausedPlayers.contains(player)) { + pausedPlayers.remove(player); + sender.sendMessage(getMessages().getComponent("commands.pausequeueserver.unpaused")); + return; + } + + pausedPlayers.add(player); + sender.sendMessage(getMessages().getComponent("commands.pausequeueserver.paused")); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return Collections.emptyList(); + } +} 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 fdc0319..00bcda2 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -11,6 +11,7 @@ import us.ajg0702.queue.api.players.QueuePlayer; 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.common.players.QueuePlayerImpl; import us.ajg0702.queue.common.utils.Debug; import us.ajg0702.utils.common.TimeUtils; @@ -195,15 +196,17 @@ public class EventHandlerImpl implements EventHandler { } - String serverName = player.getServerName(); - List svs = main.getConfig().getStringList("queue-servers"); - for(String s : svs) { - if(!s.contains(":")) continue; - String[] parts = s.split(":"); - String from = parts[0]; - QueueServer to = main.getQueueManager().findServer(parts[1]); - if(from.equalsIgnoreCase(serverName) && to != null) { - main.getQueueManager().addToQueue(player, to); + if(!PauseQueueServer.pausedPlayers.contains(player)) { + String serverName = player.getServerName(); + List svs = main.getConfig().getStringList("queue-servers"); + for(String s : svs) { + if(!s.contains(":")) continue; + String[] parts = s.split(":"); + String from = parts[0]; + QueueServer to = main.getQueueManager().findServer(parts[1]); + if(from.equalsIgnoreCase(serverName) && to != null) { + main.getQueueManager().addToQueue(player, to); + } } } 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 0973e5a..cf1d577 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java @@ -222,6 +222,9 @@ public class QueueMain extends AjQueueAPI { d.put("commands.kick.success", "Kicked {PLAYER} from {NUM} queue{s}!"); d.put("commands.kickall.usage", "Usage: /ajqueue kickall "); d.put("commands.kickall.success", "Kicked {NUM} player{s} from {SERVER}!"); + d.put("commands.pausequeueserver.unpaused", "You are no longer paused! You can now use queue-servers normally."); + d.put("commands.pausequeueserver.paused", "You are now paused! You will no longer be sent using queue-servers."); + d.put("commands.pausequeueserver.reminder", "Reminder: You are currently paused for queue-servers, so you will not be sent using them! Use /ajQueue pausequeueserver to un-pause and return to normal behaviour"); d.put("noperm", "&cYou do not have permission to do this!"); diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java index ca5395c..af92142 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -9,6 +9,7 @@ import us.ajg0702.queue.api.players.QueuePlayer; import us.ajg0702.queue.api.premium.Logic; import us.ajg0702.queue.api.queues.QueueServer; import us.ajg0702.queue.api.server.AdaptedServer; +import us.ajg0702.queue.commands.commands.manage.PauseQueueServer; import us.ajg0702.queue.common.players.QueuePlayerImpl; import us.ajg0702.queue.common.queues.QueueServerImpl; import us.ajg0702.queue.common.utils.Debug; @@ -427,6 +428,8 @@ public class QueueManagerImpl implements QueueManager { } } + protected final Map pausedAntiSpam = new ConcurrentHashMap<>(); + @Override public void sendQueueEvents() { if(main.getConfig().getBoolean("force-queue-server-target")) { @@ -440,6 +443,14 @@ public class QueueManagerImpl implements QueueManager { QueueServer to = findServer(toName); if(from == null || to == null) continue; from.getPlayers().forEach(player -> { + if(PauseQueueServer.pausedPlayers.contains(player)) { + long lastReminder = pausedAntiSpam.getOrDefault(player, 0L); + if(System.currentTimeMillis() - lastReminder > 60e3) { // 60 second cooldown on the reminder messages + player.sendMessage(main.getMessages().getComponent("commands.pausequeueserver.reminder")); + pausedAntiSpam.put(player, System.currentTimeMillis()); + } + return; + } if(!getPlayerQueues(player).contains(to)) { addToQueue(player, to); } diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeSender.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeSender.java index de75704..6171802 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeSender.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeSender.java @@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.platforms.bungeecord.BungeeQueue; +import java.util.UUID; + public class BungeeSender implements ICommandSender { final CommandSender handle; @@ -27,6 +29,12 @@ public class BungeeSender implements ICommandSender { return handle instanceof ProxiedPlayer; } + @Override + public UUID getUniqueId() throws IllegalStateException { + if(!(handle instanceof ProxiedPlayer)) throw new IllegalStateException("Cannot get UUID of non-player!"); + return ((ProxiedPlayer) handle).getUniqueId(); + } + @Override public void sendMessage(@NotNull Component message) { if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return; diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java index f443692..dff7d5a 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java @@ -20,6 +20,7 @@ import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.UUID; public class BungeePlayer implements AdaptedPlayer, Audience { @@ -172,4 +173,17 @@ public class BungeePlayer implements AdaptedPlayer, Audience { } return true; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BungeePlayer that = (BungeePlayer) o; + return handle.equals(that.handle); + } + + @Override + public int hashCode() { + return Objects.hash(handle); + } } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocitySender.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocitySender.java index b38642f..636e67a 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocitySender.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocitySender.java @@ -2,11 +2,14 @@ package us.ajg0702.queue.platforms.velocity.commands; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.jetbrains.annotations.NotNull; import us.ajg0702.queue.api.commands.ICommandSender; +import java.util.UUID; + public class VelocitySender implements ICommandSender { final CommandSource handle; @@ -26,6 +29,12 @@ public class VelocitySender implements ICommandSender { return !(handle instanceof ConsoleCommandSource); } + @Override + public UUID getUniqueId() throws IllegalStateException { + if(!(handle instanceof Player)) throw new IllegalStateException("Cannot get UUID of non-player!"); + return ((Player) handle).getUniqueId(); + } + @Override public void sendMessage(@NotNull Component message) { if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return; diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java index a362b61..5200956 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java @@ -18,6 +18,7 @@ import us.ajg0702.queue.common.QueueMain; import us.ajg0702.queue.common.utils.Debug; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -205,4 +206,17 @@ public class VelocityPlayer implements AdaptedPlayer, Audience { } return true; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + VelocityPlayer that = (VelocityPlayer) o; + return handle.equals(that.handle); + } + + @Override + public int hashCode() { + return Objects.hash(handle); + } } From 5cd13c2576afb27f34096c2e244fff0a19149812 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 16:04:16 -0700 Subject: [PATCH 06/10] Add a cooldown to the queue command (configurable) --- .../queue/commands/commands/queue/QueueCommand.java | 12 ++++++++++++ .../us/ajg0702/queue/common/EventHandlerImpl.java | 5 +++++ .../main/java/us/ajg0702/queue/common/QueueMain.java | 1 + common/src/main/resources/config.yml | 8 +++++++- 4 files changed, 25 insertions(+), 1 deletion(-) 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 From 7799ffb4342621a1bf99edf55ab564407d86f8b1 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 16:21:55 -0700 Subject: [PATCH 07/10] [nolist] change default queue cooldown to 3 seconds --- common/src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index b77b748..e74f6e3 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -314,7 +314,7 @@ give-fulljoin-players-priority: 0 force-queue-server-target: true # How long should the cooldown for queue commands be? (in seconds) -queue-command-cooldown: 15 +queue-command-cooldown: 3 # Should any server switch (including the initial join) count against the queue command cooldown? include-server-switch-in-cooldown: false From 27ba97202549600fd9ae30211b462ef10d036d54 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 17:33:03 -0700 Subject: [PATCH 08/10] Will no longer notify about an update if the update is already downloaded --- .../java/us/ajg0702/queue/common/EventHandlerImpl.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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 419ee99..fbd4581 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -146,15 +146,11 @@ public class EventHandlerImpl implements EventHandler { @Override public void onPlayerJoin(AdaptedPlayer player) { - new Thread(() -> { - try { - TimeUnit.SECONDS.sleep(2); - } catch (InterruptedException ignored) { - } - if (main.getUpdater().isUpdateAvailable() && player.hasPermission("ajqueue.manage.update")) { + main.getTaskManager().runLater(() -> { + if (main.getUpdater().isUpdateAvailable() && !main.getUpdater().isAlreadyDownloaded() && player.hasPermission("ajqueue.manage.update")) { player.sendMessage(main.getMessages().getComponent("updater.update-available")); } - }).start(); + }, 2, TimeUnit.SECONDS); ImmutableList queues = main.getQueueManager().findPlayerInQueues(player); for(QueuePlayer queuePlayer : queues) { From b0b6bbc70fdfe7b72b2d0311171e006ddf6cfd16 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Wed, 11 Jan 2023 17:34:12 -0700 Subject: [PATCH 09/10] [nolist] dont create task to run later about an update if the player doesnt have the update permission --- .../us/ajg0702/queue/common/EventHandlerImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 fbd4581..d15af1a 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -146,11 +146,13 @@ public class EventHandlerImpl implements EventHandler { @Override public void onPlayerJoin(AdaptedPlayer player) { - main.getTaskManager().runLater(() -> { - if (main.getUpdater().isUpdateAvailable() && !main.getUpdater().isAlreadyDownloaded() && player.hasPermission("ajqueue.manage.update")) { - player.sendMessage(main.getMessages().getComponent("updater.update-available")); - } - }, 2, TimeUnit.SECONDS); + if(player.hasPermission("ajqueue.manage.update")) { + main.getTaskManager().runLater(() -> { + if (main.getUpdater().isUpdateAvailable() && !main.getUpdater().isAlreadyDownloaded()) { + player.sendMessage(main.getMessages().getComponent("updater.update-available")); + } + }, 2, TimeUnit.SECONDS); + } ImmutableList queues = main.getQueueManager().findPlayerInQueues(player); for(QueuePlayer queuePlayer : queues) { From bf9b766da3f7ff7766a8d435d1f231c00bcda353 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Fri, 13 Jan 2023 13:37:19 -0700 Subject: [PATCH 10/10] [nolist] 2.3.1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8c96ca6..cd5e4b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ repositories { } allprojects { - version = "2.3.0" + version = "2.3.1" group = "us.ajg0702" plugins.apply("java")