Added balanced provider

This commit is contained in:
Jaime Martínez Rincón 2017-09-13 15:52:46 +02:00
parent 5fadacb8f0
commit 44a79c0ed9

View File

@ -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<ServerInfo> list, ProxiedPlayer player) {
List<ServerInfo> 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<ServerInfo> list, ProxiedPlayer player) {