From 44a79c0ed91d9f7531311ed6113afce0d6dba8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Wed, 13 Sep 2017 15:52:46 +0200 Subject: [PATCH] Added balanced provider --- .../connection/ProviderType.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java b/src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java index 792f89c..af2890a 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java +++ b/src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java @@ -6,6 +6,7 @@ import com.jaimemartz.playerbalancer.section.ServerSection; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -36,6 +37,28 @@ public enum ProviderType { } }, + BALANCED { + @Override + public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List list, ProxiedPlayer player) { + List results = new ArrayList<>(); + int min = Integer.MAX_VALUE; + + for (ServerInfo server : list) { + int count = plugin.getNetworkManager().getPlayers(server); + + if (count <= min) { + if (count < min) { + min = count; + results.clear(); + } + results.add(server); + } + } + + return results.get(ThreadLocalRandom.current().nextInt(list.size())); + } + }, + RANDOM { @Override public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List list, ProxiedPlayer player) {