diff --git a/api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java b/api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java index 7e75b95..ff2a62c 100644 --- a/api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java +++ b/api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java @@ -6,7 +6,7 @@ public interface ServerTimeManager { /** * Gets the time that the player specified was last seen switching servers * @param player The player to check - * @return The time that they last switched servers, in miliseconds since midnight, January 1, 1970, UTC + * @return The time that they last switched servers, in milliseconds since midnight, January 1, 1970, UTC */ long getLastServerChange(AdaptedPlayer player); } 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 28b5198..5efe06f 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -118,7 +118,19 @@ public class EventHandlerImpl implements EventHandler { player.hasPermission("ajqueue.queueserver." + to.getName()) ) ) { - main.getQueueManager().addToQueue(player, to); + int delay = Math.min(main.getConfig().getInt("queue-server-delay"), 3000); + Runnable task = () -> { + if(to.getServers().contains(player.getCurrentServer())) return; + main.getQueueManager().addToQueue(player, to); + }; + + Debug.info("Delaying queue-server by " + delay); + + if(delay > 0) { + main.getTaskManager().executor.schedule(task, delay, TimeUnit.MILLISECONDS); + } else { + task.run(); + } } } } 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 c44666d..c133677 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -470,6 +470,11 @@ public class QueueManagerImpl implements QueueManager { } return; } + long lastSwitch = main.getServerTimeManager().getLastServerChange(player); + int delay = Math.min(Math.max(main.getConfig().getInt("queue-server-delay"), 0), 3000); + if(System.currentTimeMillis() - lastSwitch > delay + 1000 || !player.getCurrentServer().equals(from)) { + return; + } if( !getPlayerQueues(player).contains(to) && ( diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 846b3d1..2012927 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -84,6 +84,13 @@ auto-add-kick-reasons: queue-servers: - 'limbo:lobbys' +# How much should we delay queueing players in queue servers? +# You should only use this if you have issues with the instant sending. +# Set to 0 or any negative number to disable +# In milliseconds. Maximum value is 3000 (3 seconds) +# Default: 0 +queue-server-delay: 0 + # Should we completely kick the user from the server if they are in a queue-server # and are kicked from the server with one of the above reasons? # Note this will do nothing on servers that aren't queue-servers @@ -382,7 +389,7 @@ debug: false # Don't touch this number please -config-version: 43 +config-version: 44 # This is ONLY here so that they can be moved to messages.yml. Please edit these in messages.yml!