From 5d76c2defbad42cd3895ebd2be190a3536c26b5b Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sat, 9 Oct 2021 11:30:29 -0700 Subject: [PATCH] wip: balancer modes --- .../java/us/ajg0702/queue/api/queues/Balancer.java | 8 ++++++++ .../java/us/ajg0702/queue/api/queues/QueueServer.java | 6 ++++++ .../us/ajg0702/queue/common/QueueManagerImpl.java | 4 +++- common/src/main/resources/config.yml | 11 ++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 api/src/main/java/us/ajg0702/queue/api/queues/Balancer.java diff --git a/api/src/main/java/us/ajg0702/queue/api/queues/Balancer.java b/api/src/main/java/us/ajg0702/queue/api/queues/Balancer.java new file mode 100644 index 0000000..331aec4 --- /dev/null +++ b/api/src/main/java/us/ajg0702/queue/api/queues/Balancer.java @@ -0,0 +1,8 @@ +package us.ajg0702.queue.api.queues; + +import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.server.AdaptedServer; + +public interface Balancer { + AdaptedServer getIdealServer(AdaptedPlayer player); +} diff --git a/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java b/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java index d860358..275a071 100644 --- a/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java +++ b/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java @@ -232,6 +232,12 @@ public interface QueueServer { */ void setSupportedProtocols(List list); + /** + * Gets the balancer this server is using + * @return The balancer this server is using + */ + Balancer getBalancer(); + /** * elliot is bad 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 ff68ca4..3485013 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -116,7 +116,9 @@ public class QueueManagerImpl implements QueueManager { return false; } - if(player.getServerName().equals(server.getName())) { + List notInServers = new ArrayList<>(server.getServers()); + notInServers.removeIf(adaptedServer -> !adaptedServer.getName().equals(player.getServerName())); + if(notInServers.size() > 0) { player.sendMessage(msgs.getComponent("errors.already-connected", "SERVER:"+server.getAlias())); return false; } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 7ddcf6b..213c1f8 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -267,4 +267,13 @@ enable-updater: true # For example, if survival is in this list, then if a player executes /survival # then they will be put in the queue for survival # This works for both servers and groups -slash-servers: [] \ No newline at end of file +slash-servers: [] + +# What balancer should we use? +# If a group is not specified here, then the default one is used +# Example entry: - bedwars: minigame +# Balancers: +# default - Will send the player to the server in the group with the least number of players +# minigame - Will send the player to the server with the most players, until that server is full, which it will then send to the next full server +balancer-types: + - bedwars: minigame \ No newline at end of file