mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-27 05:05:19 +01:00
Added balanced provider
This commit is contained in:
parent
5fadacb8f0
commit
44a79c0ed9
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user