Adds graceful shutdown for CraftBukkit #286

This commit is contained in:
2023-04-21 12:53:43 +02:00
parent 486149fa01
commit 50015c2912
3 changed files with 22 additions and 11 deletions

View File

@@ -207,7 +207,7 @@ public class Stargate extends JavaPlugin {
* @param message <p>A message describing what happened</p> * @param message <p>A message describing what happened</p>
*/ */
public static void debug(String route, String message) { public static void debug(String route, String message) {
if (stargateConfig == null || !stargateConfig.isLoaded() || stargateConfig.isDebuggingEnabled()) { if (stargateConfig == null || stargateConfig.isNotLoaded() || stargateConfig.isDebuggingEnabled()) {
logger.info("[Stargate::" + route + "] " + message); logger.info("[Stargate::" + route + "] " + message);
} else { } else {
logger.log(Level.FINEST, "[Stargate::" + route + "] " + message); logger.log(Level.FINEST, "[Stargate::" + route + "] " + message);
@@ -220,7 +220,7 @@ public class Stargate extends JavaPlugin {
* @param message <p>The message to log</p> * @param message <p>The message to log</p>
*/ */
public static void logInfo(String message) { public static void logInfo(String message) {
logger.info(getBackupString("prefix") + message); log(Level.INFO, message);
} }
/** /**
@@ -251,7 +251,7 @@ public class Stargate extends JavaPlugin {
if (logger == null) { if (logger == null) {
logger = Bukkit.getLogger(); logger = Bukkit.getLogger();
} }
if (getInstance() == null) { if (getInstance() == null || stargateConfig == null || stargateConfig.isNotLoaded()) {
logger.log(severity, "[Stargate]: " + message); logger.log(severity, "[Stargate]: " + message);
} else { } else {
logger.log(severity, getBackupString("prefix") + message); logger.log(severity, getBackupString("prefix") + message);
@@ -377,7 +377,9 @@ public class Stargate extends JavaPlugin {
public void onDisable() { public void onDisable() {
PortalHandler.closeAllPortals(); PortalHandler.closeAllPortals();
PortalRegistry.clearPortals(); PortalRegistry.clearPortals();
stargateConfig.clearManagedWorlds(); if (stargateConfig != null) {
stargateConfig.clearManagedWorlds();
}
getServer().getScheduler().cancelTasks(this); getServer().getScheduler().cancelTasks(this);
} }
@@ -399,8 +401,17 @@ public class Stargate extends JavaPlugin {
Server server = getServer(); Server server = getServer();
stargate = this; stargate = this;
stargateConfig = new StargateConfig(logger); try {
stargateConfig.finishSetup(); stargateConfig = new StargateConfig(logger);
stargateConfig.finishSetup();
} catch (NoClassDefFoundError exception) {
logSevere("Could not properly load. Class not found: " +
exception.getMessage() + "\nThis is probably because you are using CraftBukkit, or other outdated" +
"Minecraft server software. Minecraft server software based on Spigot or Paper is required. Paper" +
" is recommended, and can be downloaded at: https://papermc.io/downloads/paper");
this.onDisable();
return;
}
pluginVersion = pluginDescriptionFile.getVersion(); pluginVersion = pluginDescriptionFile.getVersion();

View File

@@ -45,7 +45,7 @@ public final class LanguageLoader {
loadedBackupStrings = load("en", inputStream); loadedBackupStrings = load("en", inputStream);
} else { } else {
loadedBackupStrings = null; loadedBackupStrings = null;
Stargate.getConsoleLogger().severe("[stargate] Error loading backup language. " + Stargate.logSevere("Error loading backup language. " +
"There may be missing text in-game"); "There may be missing text in-game");
} }
} }
@@ -226,7 +226,7 @@ public final class LanguageLoader {
strings = FileHelper.readKeyValuePairs(bufferedReader, "=", ColorConversion.NORMAL); strings = FileHelper.readKeyValuePairs(bufferedReader, "=", ColorConversion.NORMAL);
} catch (Exception e) { } catch (Exception e) {
if (Stargate.getStargateConfig().isDebuggingEnabled()) { if (Stargate.getStargateConfig().isDebuggingEnabled()) {
Stargate.getConsoleLogger().info("[Stargate] Unable to load language " + lang); Stargate.logInfo("Unable to load language " + lang);
} }
return null; return null;
} }

View File

@@ -118,10 +118,10 @@ public final class StargateConfig {
/** /**
* Gets whether this configuration has been fully loaded * Gets whether this configuration has been fully loaded
* *
* @return <p>True if fully loaded</p> * @return <p>True if not fully loaded</p>
*/ */
public boolean isLoaded() { public boolean isNotLoaded() {
return this.isLoaded; return !this.isLoaded;
} }
/** /**