Return if the proxy is disabling

feat/data-edit-commands
William 3 years ago
parent cf6b81200b
commit d4dbb5fe7d

@ -31,6 +31,7 @@ public final class HuskSyncBungeeCord extends Plugin {
private static final int METRICS_ID = 13141; private static final int METRICS_ID = 13141;
private static HuskSyncBungeeCord instance; private static HuskSyncBungeeCord instance;
public static HuskSyncBungeeCord getInstance() { public static HuskSyncBungeeCord getInstance() {
return instance; return instance;
} }
@ -38,12 +39,16 @@ public final class HuskSyncBungeeCord extends Plugin {
// Whether the plugin is ready to accept redis messages // Whether the plugin is ready to accept redis messages
public static boolean readyForRedis = false; 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<Server> synchronisedServers; public static HashSet<Server> synchronisedServers;
private static HashMap<String,Database> clusterDatabases; private static HashMap<String, Database> clusterDatabases;
public static Connection getConnection(String clusterId) throws SQLException { public static Connection getConnection(String clusterId) throws SQLException {
return clusterDatabases.get(clusterId).getConnection(); return clusterDatabases.get(clusterId).getConnection();
} }
@ -78,6 +83,7 @@ public final class HuskSyncBungeeCord extends Plugin {
} }
// Initialize the database // Initialize the database
clusterDatabases = new HashMap<>();
for (Settings.SynchronisationCluster cluster : Settings.clusters) { for (Settings.SynchronisationCluster cluster : Settings.clusters) {
Database clusterDatabase = switch (Settings.dataStorageType) { Database clusterDatabase = switch (Settings.dataStorageType) {
case SQLITE -> new SQLite(this, cluster); case SQLITE -> new SQLite(this, cluster);
@ -134,9 +140,10 @@ public final class HuskSyncBungeeCord extends Plugin {
@Override @Override
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
isDisabling = true;
// Send terminating handshake message // Send terminating handshake message
for (Server server: synchronisedServers) { for (Server server : synchronisedServers) {
try { try {
new RedisMessage(RedisMessage.MessageType.TERMINATE_HANDSHAKE, new RedisMessage(RedisMessage.MessageType.TERMINATE_HANDSHAKE,
new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null, server.clusterId()), new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null, server.clusterId()),
@ -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 * 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) {
}
} }

@ -131,6 +131,7 @@ public class BungeeRedisListener extends RedisListener {
} }
case CONNECTION_HANDSHAKE -> { case CONNECTION_HANDSHAKE -> {
// Reply to a Bukkit server's connection handshake to complete the process // 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 UUID serverUUID = UUID.fromString(message.getMessageDataElements()[0]);
final boolean hasMySqlPlayerDataBridge = Boolean.parseBoolean(message.getMessageDataElements()[1]); final boolean hasMySqlPlayerDataBridge = Boolean.parseBoolean(message.getMessageDataElements()[1]);
final String bukkitBrand = message.getMessageDataElements()[2]; final String bukkitBrand = message.getMessageDataElements()[2];

Loading…
Cancel
Save