Prevent more than 5 players from being processed at a time on server connect.

This commit is contained in:
Jonathan Williams 2014-10-27 04:35:05 -07:00
parent e926fc1f10
commit 006e20bb13

View File

@ -48,6 +48,8 @@ public class CoreClientManager extends MiniPlugin
private Object _clientLock = new Object(); private Object _clientLock = new Object();
private static int _connectingClients = 0;
public CoreClientManager(JavaPlugin plugin, String webServer) public CoreClientManager(JavaPlugin plugin, String webServer)
{ {
super("Client Manager", plugin); super("Client Manager", plugin);
@ -122,6 +124,20 @@ public class CoreClientManager extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void AsyncLogin(AsyncPlayerPreLoginEvent event) public void AsyncLogin(AsyncPlayerPreLoginEvent event)
{ {
while (_connectingClients >= 5)
{
try
{
Thread.sleep(25);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
_connectingClients++;
try try
{ {
LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress()); LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress());
@ -134,6 +150,10 @@ public class CoreClientManager extends MiniPlugin
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
} }
finally
{
_connectingClients--;
}
if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR)) if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR))
{ {