From 3640b6ca9886c34a4af9c2e0d523d7748dbe4d4f Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 17 Mar 2021 23:33:10 +0100 Subject: [PATCH] New attempt to disconnect players when lobbies restarts... --- .../themcgamer/proxy/hub/HubBalancer.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java b/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java index 760d252..3b4ef60 100644 --- a/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java +++ b/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java @@ -50,23 +50,6 @@ public class HubBalancer implements Runnable, Listener { if (jedisCommand instanceof ServerRestartCommand) { ServerRestartCommand serverRestartCommand = (ServerRestartCommand) jedisCommand; removeServer(serverRestartCommand.getServerId()); - ServerInfo serverInfo = proxy.getProxy().getServerInfo(serverRestartCommand.getServerId()); - if (serverInfo == null) { - System.out.println("ServerInfo is null"); - //We do this check due sometimes players stay in a server which is deleted. But were send to it before it was deleted. - for (ProxiedPlayer player : proxy.getProxy().getPlayers()) { - if (player.getServer() == null && (hubs.size() == 0)) - kickPlayer(player, NO_AVAILABLE_HUB); - } - return; - } else { - for (ProxiedPlayer player : proxy.getProxy().getPlayers()) { - if (player.getServer().getInfo().equals(serverInfo)) { - if (hubs.isEmpty()) - kickPlayer(player, NO_AVAILABLE_HUB); - } - } - } } if (jedisCommand instanceof ServerStateChangeCommand) { ServerStateChangeCommand serverStateChangeCommand = (ServerStateChangeCommand) jedisCommand; @@ -233,6 +216,15 @@ public class HubBalancer implements Runnable, Listener { if (entry.getValue().getMotd().equals("STATIC")) return false; hubs.remove(serverId); + if (hubs.size() <= 0) { + System.out.println(hubs.size()); + System.out.println("Kicking players from server" + entry.getValue().getName()); + entry.getValue().getPlayers().forEach(proxiedPlayer -> kickPlayer(proxiedPlayer, NO_AVAILABLE_HUB)); + } else { + System.out.println(hubs.size()); + System.out.println("Movings players from server " + entry.getValue().getName()); + entry.getValue().getPlayers().forEach(this::sendToHub); + } return true; }); }