From f8564e4e3feeed0ae256de021fbceba7bca15831 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Wed, 19 Aug 2020 20:31:20 +0200 Subject: [PATCH] Disable plugin on load error --- .../bluemap/bukkit/BukkitPlugin.java | 16 ++++++++-------- .../bluecolored/bluemap/fabric/FabricMod.java | 1 + .../de/bluecolored/bluemap/forge/ForgeMod.java | 1 + .../bluemap/sponge/SpongePlugin.java | 17 +++++++++-------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java b/BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java index 0cfa0005..eebb7249 100644 --- a/BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java +++ b/BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java @@ -62,7 +62,7 @@ public class BukkitPlugin extends JavaPlugin implements ServerInterface, Listene private static BukkitPlugin instance; - private Plugin bluemap; + private Plugin pluginInstance; private EventForwarder eventForwarder; private BukkitCommands commands; @@ -77,8 +77,8 @@ public BukkitPlugin() { this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>()); this.eventForwarder = new EventForwarder(); - this.bluemap = new Plugin("bukkit", this); - this.commands = new BukkitCommands(this.bluemap); + this.pluginInstance = new Plugin("bukkit", this); + this.commands = new BukkitCommands(this.pluginInstance); BukkitPlugin.instance = this; } @@ -130,11 +130,11 @@ public void onEnable() { getServer().getScheduler().runTaskAsynchronously(this, () -> { try { Logger.global.logInfo("Loading..."); - this.bluemap.load(); - if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!"); + this.pluginInstance.load(); + if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!"); } catch (IOException | ParseResourceException | RuntimeException e) { Logger.global.logError("Failed to load!", e); - this.bluemap.unload(); + this.pluginInstance.unload(); } }); } @@ -143,7 +143,7 @@ public void onEnable() { public void onDisable() { Logger.global.logInfo("Stopping..."); getServer().getScheduler().cancelTasks(this); - bluemap.unload(); + pluginInstance.unload(); Logger.global.logInfo("Saved and stopped!"); } @@ -209,7 +209,7 @@ public File getConfigFolder() { } public Plugin getBlueMap() { - return bluemap; + return pluginInstance; } public static BukkitPlugin getInstance() { diff --git a/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 3ee2d02b..70cbedac 100644 --- a/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -114,6 +114,7 @@ public void onInitialize() { if (pluginInstance.isLoaded()) Logger.global.logInfo("BlueMap loaded!"); } catch (IOException | ParseResourceException e) { Logger.global.logError("Failed to load bluemap!", e); + pluginInstance.unload(); } }).start(); }); diff --git a/BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 992d6914..ea047f9f 100644 --- a/BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -115,6 +115,7 @@ public void onServerStarting(FMLServerStartingEvent event) { if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!"); } catch (IOException | ParseResourceException e) { Logger.global.logError("Failed to load bluemap!", e); + pluginInstance.unload(); } }).start(); } diff --git a/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java b/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java index 0237bcc8..3ae5c0f9 100644 --- a/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java +++ b/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java @@ -79,7 +79,7 @@ public class SpongePlugin implements ServerInterface { @Inject private MetricsLite2 metrics; - private Plugin bluemap; + private Plugin pluginInstance; private SpongeCommands commands; private SpongeExecutorService asyncExecutor; @@ -95,8 +95,8 @@ public SpongePlugin(org.slf4j.Logger logger) { this.onlinePlayerMap = new ConcurrentHashMap<>(); this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>()); - this.bluemap = new Plugin("sponge", this); - this.commands = new SpongeCommands(bluemap); + this.pluginInstance = new Plugin("sponge", this); + this.commands = new SpongeCommands(pluginInstance); } @Listener @@ -122,10 +122,11 @@ public void onServerStart(GameStartingServerEvent evt) { asyncExecutor.execute(() -> { try { Logger.global.logInfo("Loading..."); - bluemap.load(); - if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!"); + pluginInstance.load(); + if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!"); } catch (IOException | ParseResourceException | RuntimeException e) { Logger.global.logError("Failed to load!", e); + pluginInstance.unload(); } }); } @@ -134,7 +135,7 @@ public void onServerStart(GameStartingServerEvent evt) { public void onServerStop(GameStoppingEvent evt) { Logger.global.logInfo("Stopping..."); Sponge.getScheduler().getScheduledTasks(this).forEach(t -> t.cancel()); - bluemap.unload(); + pluginInstance.unload(); Logger.global.logInfo("Saved and stopped!"); } @@ -143,11 +144,11 @@ public void onServerReload(GameReloadEvent evt) { asyncExecutor.execute(() -> { try { Logger.global.logInfo("Reloading..."); - bluemap.reload(); + pluginInstance.reload(); Logger.global.logInfo("Reloaded!"); } catch (IOException | ParseResourceException | RuntimeException e) { Logger.global.logError("Failed to load!", e); - bluemap.unload(); + pluginInstance.unload(); } }); }