Revert the revert of the revert.

This commit is contained in:
Jonathan Williams 2014-12-14 22:58:49 -05:00
parent d1be64d7e7
commit e02bcd8b84

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import mineplex.core.MiniPlugin;
import mineplex.core.account.command.UpdateRank;
@ -48,8 +49,8 @@ public class CoreClientManager extends MiniPlugin
private Object _clientLock = new Object();
private static int _clientsConnecting = 0;
private static int _clientsProcessing = 0;
private static AtomicInteger _clientsConnecting = new AtomicInteger(0);
private static AtomicInteger _clientsProcessing = new AtomicInteger(0);
public CoreClientManager(JavaPlugin plugin, String webServer)
{
@ -124,14 +125,16 @@ public class CoreClientManager extends MiniPlugin
public int getPlayerCountIncludingConnecting()
{
return Bukkit.getOnlinePlayers().size() + _clientsConnecting;
return Bukkit.getOnlinePlayers().size() + Math.max(0, _clientsConnecting.get());
}
@EventHandler(priority = EventPriority.LOWEST)
public void AsyncLogin(AsyncPlayerPreLoginEvent event)
{
_clientsConnecting++;
while (_clientsProcessing >= 5)
try
{
_clientsConnecting.incrementAndGet();
while (_clientsProcessing.get() >= 5)
{
try
{
@ -143,24 +146,20 @@ public class CoreClientManager extends MiniPlugin
}
}
_clientsProcessing++;
try
{
_clientsProcessing.incrementAndGet();
LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress());
}
catch(Exception exception)
{
Logger.Instance.log(exception);
event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute.");
System.out.println(exception.getMessage());
}
finally
{
_clientsProcessing--;
_clientsConnecting--;
_clientsProcessing.decrementAndGet();
}
if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR))
@ -176,6 +175,11 @@ public class CoreClientManager extends MiniPlugin
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
}
}
finally
{
_clientsConnecting.decrementAndGet();
}
}
public void loadClientByName(final String playerName, final Runnable runnable)
{
@ -436,6 +440,18 @@ public class CoreClientManager extends MiniPlugin
}
}
@EventHandler
public void debug(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
return;
System.out.println("=====");
System.out.println("Connecting : " + _clientsConnecting.get());
System.out.println("Processing : " + _clientsProcessing.get());
System.out.println("=====");
}
public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
{
_loginProcessors.put(processor.getName(), processor);