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) {