From 7eb8b8c6143928161aa32e8c25dda47318fa3132 Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 20 Feb 2021 03:29:58 +0100 Subject: [PATCH 1/3] Probs made a fix so players won't stuck in a lobby anymore, when all lobbies are restarting. --- .../zone/themcgamer/proxy/hub/HubBalancer.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 daa4f84..48c9037 100644 --- a/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java +++ b/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java @@ -11,6 +11,7 @@ import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; import zone.themcgamer.common.Tuple; import zone.themcgamer.data.jedis.command.JedisCommandHandler; +import zone.themcgamer.data.jedis.command.impl.ServerRestartCommand; import zone.themcgamer.data.jedis.command.impl.ServerStateChangeCommand; import zone.themcgamer.data.jedis.data.ServerGroup; import zone.themcgamer.data.jedis.data.server.MinecraftServer; @@ -46,6 +47,20 @@ public class HubBalancer implements Runnable, Listener { proxy.getProxy().getPluginManager().registerListener(proxy, this); JedisCommandHandler.getInstance().addListener(jedisCommand -> { + if (jedisCommand instanceof ServerRestartCommand) { + ServerRestartCommand serverRestartCommand = (ServerRestartCommand) jedisCommand; + ServerInfo serverInfo = proxy.getProxy().getServerInfo(serverRestartCommand.getServerId()); + if (serverInfo == null) + return; + for (ProxiedPlayer player : proxy.getProxy().getPlayers()) { + if (player.getServer().getInfo().equals(serverInfo)) { + if (hubs.isEmpty() || hubs.size() == 1) + kickPlayer(player, NO_AVAILABLE_HUB); + } + } + if (hubs.containsValue(serverInfo)) + hubs.remove(serverRestartCommand.getServerId()); + } if (jedisCommand instanceof ServerStateChangeCommand) { ServerStateChangeCommand serverStateChangeCommand = (ServerStateChangeCommand) jedisCommand; System.out.println("Received update status from server " + serverStateChangeCommand.getServer().getId() + " status: " + serverStateChangeCommand.getNewState()); From b50aa92f76790d75ac92c27ffd63e8fd708bf1fd Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 20 Feb 2021 03:46:33 +0100 Subject: [PATCH 2/3] Made a method HubBalancer#removeServer since the code was duplicated. --- .../themcgamer/proxy/hub/HubBalancer.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 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 48c9037..470243b 100644 --- a/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java +++ b/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java @@ -49,17 +49,24 @@ public class HubBalancer implements Runnable, Listener { JedisCommandHandler.getInstance().addListener(jedisCommand -> { if (jedisCommand instanceof ServerRestartCommand) { ServerRestartCommand serverRestartCommand = (ServerRestartCommand) jedisCommand; + removeServer(serverRestartCommand.getServerId()); ServerInfo serverInfo = proxy.getProxy().getServerInfo(serverRestartCommand.getServerId()); - if (serverInfo == null) - return; - for (ProxiedPlayer player : proxy.getProxy().getPlayers()) { - if (player.getServer().getInfo().equals(serverInfo)) { - if (hubs.isEmpty() || hubs.size() == 1) + 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 || player.getServer().getInfo().getName().equals(serverRestartCommand.getServerId())) kickPlayer(player, NO_AVAILABLE_HUB); } + return; + } else { + for (ProxiedPlayer player : proxy.getProxy().getPlayers()) { + if (player.getServer().getInfo().equals(serverInfo)) { + if (hubs.isEmpty() || hubs.size() <= 1) + kickPlayer(player, NO_AVAILABLE_HUB); + } + } } - if (hubs.containsValue(serverInfo)) - hubs.remove(serverRestartCommand.getServerId()); } if (jedisCommand instanceof ServerStateChangeCommand) { ServerStateChangeCommand serverStateChangeCommand = (ServerStateChangeCommand) jedisCommand; @@ -69,17 +76,7 @@ public class HubBalancer implements Runnable, Listener { if (!serverStateChangeCommand.getNewState().isShuttingDownState()) return; MinecraftServer server = serverStateChangeCommand.getServer(); - proxy.getProxy().getServers().entrySet().removeIf(entry -> { - String key = entry.getKey(); - if (!key.equals(server.getId())) - return false; - if (key.equals(group.getName())) - return false; - if (entry.getValue().getMotd().equals("STATIC")) - return false; - hubs.remove(server.getId()); - return true; - }); + removeServer(server.getId()); } }); } @@ -225,4 +222,18 @@ public class HubBalancer implements Runnable, Listener { "&b" + reason + "\n" + "&7"))); } + + private void removeServer(String serverId) { + proxy.getProxy().getServers().entrySet().removeIf(entry -> { + String key = entry.getKey(); + if (!key.equals(serverId)) + return false; + if (key.equals(group.getName())) + return false; + if (entry.getValue().getMotd().equals("STATIC")) + return false; + hubs.remove(serverId); + return true; + }); + } } \ No newline at end of file From 6f3c62b46474f1cae88dcf7be156741d802f5cf8 Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 20 Feb 2021 04:02:55 +0100 Subject: [PATCH 3/3] Fixed lobby checks --- .../main/java/zone/themcgamer/proxy/hub/HubBalancer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 470243b..760d252 100644 --- a/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java +++ b/proxy/src/main/java/zone/themcgamer/proxy/hub/HubBalancer.java @@ -55,14 +55,14 @@ public class HubBalancer implements Runnable, Listener { 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 || player.getServer().getInfo().getName().equals(serverRestartCommand.getServerId())) + 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() || hubs.size() <= 1) + if (hubs.isEmpty()) kickPlayer(player, NO_AVAILABLE_HUB); } } @@ -101,7 +101,7 @@ public class HubBalancer implements Runnable, Listener { kickPlayer(player, HUB_SEND_FAILED); event.setCancelled(true); } else event.setTarget(serverInfo); - } else if (reason == ServerConnectEvent.Reason.LOBBY_FALLBACK) { + } else if (reason == ServerConnectEvent.Reason.LOBBY_FALLBACK || (event.getTarget().isRestricted())) { kickPlayer(player, NO_AVAILABLE_HUB); event.setCancelled(true); }