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,56 +125,59 @@ 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
{
Thread.sleep(25);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
_clientsProcessing++;
try
{
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--;
}
if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR))
{
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers())
_clientsConnecting.incrementAndGet();
while (_clientsProcessing.get() >= 5)
{
if (player.getName().equalsIgnoreCase(event.getName()))
try
{
return;
Thread.sleep(25);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
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.decrementAndGet();
}
if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR))
{
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers())
{
if (player.getName().equalsIgnoreCase(event.getName()))
{
return;
}
}
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
}
}
finally
{
_clientsConnecting.decrementAndGet();
}
}
@ -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);