From 7fb679e7f5476bcb749da8a5f719ccba63ebee34 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 8 Nov 2014 14:32:24 -0800 Subject: [PATCH] Changed lobbyBalancer to send one player to each lobby that wasn't full. --- .../bungee/lobbyBalancer/LobbyBalancer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index 27ecb38c5..e487f2d4e 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Random; import java.util.concurrent.TimeUnit; import mineplex.serverdata.MinecraftServer; @@ -26,7 +25,7 @@ public class LobbyBalancer implements Listener, Runnable private List _sortedLobbies = new ArrayList(); private static Object _serverLock = new Object(); - private Random _random = new Random(); + private int _lobbyIndex = 0; public LobbyBalancer(Plugin plugin) { @@ -49,12 +48,13 @@ public class LobbyBalancer implements Listener, Runnable synchronized (_serverLock) { - Collections.sort(_sortedLobbies, new LobbySorter()); + if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount()) + _lobbyIndex = 0; - int lobbyIndex = _random.nextInt(Math.min(10, _sortedLobbies.size())); - event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(lobbyIndex).getName())); - _sortedLobbies.get(lobbyIndex).incrementPlayerCount(1); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(lobbyIndex).getName() + "(" + _sortedLobbies.get(lobbyIndex).getPublicAddress() + ")"); + event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName())); + _sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1); + System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")"); + _lobbyIndex++; } } @@ -95,6 +95,8 @@ public class LobbyBalancer implements Listener, Runnable if (timeSpentInLock > 50) System.out.println("[==] TIMING [==] Locked loading servers for " + timeSpentInLock + "ms"); + + _lobbyIndex = 0; } } }