From 006e20bb13522537fc02cdc6f4b1102f28615b07 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 27 Oct 2014 04:35:05 -0700 Subject: [PATCH] Prevent more than 5 players from being processed at a time on server connect. --- .../core/account/CoreClientManager.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 92fb4215d..94034eee6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -48,6 +48,8 @@ public class CoreClientManager extends MiniPlugin private Object _clientLock = new Object(); + private static int _connectingClients = 0; + public CoreClientManager(JavaPlugin plugin, String webServer) { super("Client Manager", plugin); @@ -122,6 +124,20 @@ public class CoreClientManager extends MiniPlugin @EventHandler(priority = EventPriority.LOWEST) public void AsyncLogin(AsyncPlayerPreLoginEvent event) { + while (_connectingClients >= 5) + { + try + { + Thread.sleep(25); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + _connectingClients++; + try { LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress()); @@ -134,6 +150,10 @@ public class CoreClientManager extends MiniPlugin System.out.println(exception.getMessage()); } + finally + { + _connectingClients--; + } if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR)) {