Skip to content

Commit

Permalink
Add option to delay queue-servers by up to 3 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Oct 21, 2023
1 parent b0892dd commit e8ca809
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Expand Up @@ -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);
}
Expand Up @@ -118,7 +118,19 @@ public void onPlayerJoinServer(AdaptedPlayer player) {
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();
}
}
}
}
Expand Down
Expand Up @@ -470,6 +470,11 @@ public void sendQueueEvents() {
}
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) &&
(
Expand Down
9 changes: 8 additions & 1 deletion common/src/main/resources/config.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit e8ca809

Please sign in to comment.