From 12a6cd4f7c826a59a492a84f24d5b1bcce3b9638 Mon Sep 17 00:00:00 2001 From: Allink Date: Sun, 15 May 2022 01:47:33 +0100 Subject: [PATCH] Shutdown the server instead of attempting to load new BukkitTelnet in place over old one --- .../automation/PatchedTelnetCompiler.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java b/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java index dac582e..3491ded 100644 --- a/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java +++ b/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java @@ -3,7 +3,10 @@ package dev.plex.automation; import com.google.common.collect.ImmutableList; import dev.plex.BukkitTelnetModule; import dev.plex.util.PlexLog; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -41,18 +44,6 @@ public class PatchedTelnetCompiler public static void execute() throws Exception { - // Check if incorrect BukkitTelnet plugin is present - if (PLUGIN_MANAGER.isPluginEnabled("BukkitTelnet")) - { - Plugin plugin = PLUGIN_MANAGER.getPlugin("BukkitTelnet"); - if (plugin == null) throw new IllegalStateException("Unpatched BukkitTelnet cannot be null while enabled!"); - PLUGIN_MANAGER.disablePlugin(plugin); - - Path path = Path.of(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); - Files.delete(path); - } - - // Create directories final List directories = ImmutableList.of(ROOT_PATH, EXTRACT_TARGET); @@ -192,8 +183,33 @@ public class PatchedTelnetCompiler } Timer timer = new Timer(); + Plugin plugin = null; - final Plugin plugin = PLUGIN_MANAGER.loadPlugin(TARGET_PLUGIN); + // Check if incorrect BukkitTelnet plugin is present + if (PLUGIN_MANAGER.isPluginEnabled("BukkitTelnet")) + { + PlexLog.warn("Stopping server since unpatched BukkitTelnet was already loaded, please restart and it should work!"); + // Running stop doesn't seem to work... + + Bukkit.savePlayers(); + + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) + { + onlinePlayer.kick(Component.text("Server is restarting due to a plugin upgrade, please wait!")); + } + + for (World world : Bukkit.getWorlds()) + { + Bukkit.unloadWorld(world, true); + } + + Runtime.getRuntime().halt(0); + return; + } + else + { + plugin = PLUGIN_MANAGER.loadPlugin(TARGET_PLUGIN); + } if (plugin == null) throw new IllegalStateException("BukkitTelnet cannot be null after successful compile!"); plugin.onLoad();