Changed lobbyBalancer to send one player to each lobby that wasn't full.

This commit is contained in:
Jonathan Williams 2014-11-08 14:32:24 -08:00
parent 5ce38c3030
commit 7fb679e7f5

View File

@ -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<MinecraftServer> _sortedLobbies = new ArrayList<MinecraftServer>();
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;
}
}
}