From fdbb4b3df1a98a514afb3065999e781784694cfb Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 23 Jul 2026 19:29:06 -0600 Subject: [PATCH] Fix proxy reload listener lifecycle --- .../votifier/bungee/VotifierPlusBungee.java | 22 +++++-- .../votifier/bungee/VotifierPlusCommand.java | 2 +- .../velocity/VotifierPlusVelocity.java | 62 +++++++++++-------- .../velocity/VotifierPlusVelocityCommand.java | 10 ++- 4 files changed, 61 insertions(+), 35 deletions(-) diff --git a/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusBungee.java b/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusBungee.java index f48b77d..8d6ffe9 100644 --- a/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusBungee.java +++ b/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusBungee.java @@ -125,11 +125,23 @@ public void loadVersionFile() { } } - public void reload() { - config.load(); - loadTokens(); - loadVoteReceiver(); - } + public void reload() { + if (voteReceiver != null) { + voteReceiver.shutdown(); + voteReceiver = null; + } + config.load(); + loadTokens(); + loadVoteReceiver(); + } + + @Override + public void onDisable() { + if (voteReceiver != null) { + voteReceiver.shutdown(); + voteReceiver = null; + } + } private void loadVoteReceiver() { try { diff --git a/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusCommand.java b/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusCommand.java index 95c435a..b4a1d87 100644 --- a/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusCommand.java +++ b/VotifierPlus/src/main/java/com/vexsoftware/votifier/bungee/VotifierPlusCommand.java @@ -48,7 +48,7 @@ public void execute(CommandSender sender, String[] args) { } sender.sendMessage(new TextComponent("New keys generated")); } - if (args[0].equalsIgnoreCase("vote") && args.length > 2) { + if ((args[0].equalsIgnoreCase("test") || args[0].equalsIgnoreCase("vote")) && args.length > 2) { try { PublicKey publicKey = bungee.getKeyPair().getPublic(); String serverIP = bungee.getConfig().getHost(); diff --git a/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocity.java b/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocity.java index 44071bc..bb4d4b3 100644 --- a/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocity.java +++ b/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocity.java @@ -74,9 +74,12 @@ public VotifierPlusVelocity(ProxyServer server, Logger logger, Metrics.Factory m this.metricsFactory = metricsFactory; } - @Subscribe - public void onProxyDisable(ProxyShutdownEvent event) { - voteReceiver.shutdown(); + @Subscribe + public void onProxyDisable(ProxyShutdownEvent event) { + if (voteReceiver != null) { + voteReceiver.shutdown(); + voteReceiver = null; + } } private HashMap tokens = new HashMap(); @@ -184,8 +187,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) { // Specify other aliases (optional) .aliases("votifierplus", "votifierplusvelocity").build(); server.getCommandManager().register(meta, new VotifierPlusVelocityCommand(this)); - loadVoteReceiver(); - File rsaDirectory = new File(dataDirectory.toFile(), "rsa"); + File rsaDirectory = new File(dataDirectory.toFile(), "rsa"); /* * Create RSA directory and keys if it does not exist; otherwise, read keys. */ @@ -197,10 +199,11 @@ public void onProxyInitialization(ProxyInitializeEvent event) { } else { keyPair = RSAIO.load(rsaDirectory); } - } catch (Exception ex) { - logger.error("Error reading configuration file or RSA keys"); - return; - } + } catch (Exception ex) { + logger.error("Error reading configuration file or RSA keys"); + return; + } + loadVoteReceiver(); try { getVersionFile(); @@ -224,9 +227,9 @@ public void onProxyInitialization(ProxyInitializeEvent event) { } - private void loadVoteReceiver() { - try { - voteReceiver = new VoteReceiver(config.getHost(), config.getPort()) { + private boolean loadVoteReceiver() { + try { + VoteReceiver receiver = new VoteReceiver(config.getHost(), config.getPort()) { @Override public void logWarning(String warn) { @@ -353,17 +356,24 @@ public ThrottleConfig getThrottleConfig() { } }; - voteReceiver.start(); - - logger.info("Votifier enabled."); - } catch (Exception ex) { - return; - } - } - - public void reload() { - config.reload(); - loadTokens(); - loadVoteReceiver(); - } -} + receiver.start(); + voteReceiver = receiver; + + logger.info("Votifier enabled."); + return true; + } catch (Exception ex) { + logger.error("Unable to start Votifier vote receiver.", ex); + return false; + } + } + + public boolean reload() { + if (voteReceiver != null) { + voteReceiver.shutdown(); + voteReceiver = null; + } + config.reload(); + loadTokens(); + return loadVoteReceiver(); + } +} diff --git a/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocityCommand.java b/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocityCommand.java index 09bb5d7..31b6121 100644 --- a/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocityCommand.java +++ b/VotifierPlus/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlusVelocityCommand.java @@ -31,8 +31,12 @@ public void execute(final Invocation invocation) { if (hasPermission(invocation)) { if (args.length > 0) { if (args[0].equalsIgnoreCase("reload")) { - plugin.reload(); - source.sendMessage(Component.text("Reloading VotifierPlus").color(NamedTextColor.AQUA)); + if (plugin.reload()) { + source.sendMessage(Component.text("Reloaded VotifierPlus").color(NamedTextColor.AQUA)); + } else { + source.sendMessage(Component.text("Failed to reload VotifierPlus; check the proxy log.") + .color(NamedTextColor.RED)); + } } if (args[0].equalsIgnoreCase("GenerateKeys")) { File rsaDirectory = new File(plugin.getDataDirectory() + File.separator + "rsa"); @@ -52,7 +56,7 @@ public void execute(final Invocation invocation) { } source.sendMessage(Component.text("New keys generated")); } - if (args[0].equalsIgnoreCase("vote") && args.length > 2) { + if ((args[0].equalsIgnoreCase("test") || args[0].equalsIgnoreCase("vote")) && args.length > 2) { try { PublicKey publicKey = plugin.getKeyPair().getPublic(); String serverIP = plugin.getConfig().getHost();