From d4dbb5fe7df51119f5aa2d94794cb191249a3544 Mon Sep 17 00:00:00 2001 From: William Date: Mon, 15 Nov 2021 17:53:06 +0000 Subject: [PATCH] Return if the proxy is disabling --- .../husksync/HuskSyncBungeeCord.java | 19 ++++++++++++++----- .../listener/BungeeRedisListener.java | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java b/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java index 84750549..f3ab7ca2 100644 --- a/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java +++ b/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java @@ -31,6 +31,7 @@ public final class HuskSyncBungeeCord extends Plugin { private static final int METRICS_ID = 13141; private static HuskSyncBungeeCord instance; + public static HuskSyncBungeeCord getInstance() { return instance; } @@ -38,12 +39,16 @@ public final class HuskSyncBungeeCord extends Plugin { // Whether the plugin is ready to accept redis messages public static boolean readyForRedis = false; + // Whether the plugin is in the process of disabling and should skip responding to handshake confirmations + public static boolean isDisabling = false; + /** - Set of all the {@link Server}s that have completed the synchronisation handshake with HuskSync on the proxy + * Set of all the {@link Server}s that have completed the synchronisation handshake with HuskSync on the proxy */ public static HashSet synchronisedServers; - private static HashMap clusterDatabases; + private static HashMap clusterDatabases; + public static Connection getConnection(String clusterId) throws SQLException { return clusterDatabases.get(clusterId).getConnection(); } @@ -78,6 +83,7 @@ public final class HuskSyncBungeeCord extends Plugin { } // Initialize the database + clusterDatabases = new HashMap<>(); for (Settings.SynchronisationCluster cluster : Settings.clusters) { Database clusterDatabase = switch (Settings.dataStorageType) { case SQLITE -> new SQLite(this, cluster); @@ -134,15 +140,16 @@ public final class HuskSyncBungeeCord extends Plugin { @Override public void onDisable() { // Plugin shutdown logic + isDisabling = true; // Send terminating handshake message - for (Server server: synchronisedServers) { + for (Server server : synchronisedServers) { try { new RedisMessage(RedisMessage.MessageType.TERMINATE_HANDSHAKE, new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null, server.clusterId()), server.serverUUID().toString(), ProxyServer.getInstance().getName()).send(); - } catch (IOException e) { + } catch (IOException e) { getInstance().getLogger().log(Level.SEVERE, "Failed to serialize Redis message for handshake termination", e); } } @@ -159,5 +166,7 @@ public final class HuskSyncBungeeCord extends Plugin { /** * A record representing a server synchronised on the network and whether it has MySqlPlayerDataBridge installed */ - public record Server(UUID serverUUID, boolean hasMySqlPlayerDataBridge, String huskSyncVersion, String serverBrand, String clusterId) { } + public record Server(UUID serverUUID, boolean hasMySqlPlayerDataBridge, String huskSyncVersion, String serverBrand, + String clusterId) { + } } diff --git a/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java index 3a3cacf9..807423ed 100644 --- a/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java @@ -131,6 +131,7 @@ public class BungeeRedisListener extends RedisListener { } case CONNECTION_HANDSHAKE -> { // Reply to a Bukkit server's connection handshake to complete the process + if (HuskSyncBungeeCord.isDisabling) return; // Return if the Proxy is disabling final UUID serverUUID = UUID.fromString(message.getMessageDataElements()[0]); final boolean hasMySqlPlayerDataBridge = Boolean.parseBoolean(message.getMessageDataElements()[1]); final String bukkitBrand = message.getMessageDataElements()[2];