From 8217ff18360a59166d437027c1f3b35b79c7ebc9 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 13 May 2011 18:17:28 -0700 Subject: [PATCH] Fixed errors during plugin enable/disable leaving Bukkit in an undefined state. Previous fix would at least prevent plugins from breaking the server, but it aborted the enable/disable process prematurely. By: sk89q --- .../org/bukkit/plugin/SimplePluginManager.java | 10 ++++++---- .../org/bukkit/plugin/java/JavaPluginLoader.java | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 7d0ebd2c47..eb8d47d071 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -249,7 +249,7 @@ public final class SimplePluginManager implements PluginManager { try { plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable ex) { - server.getLogger().log(Level.SEVERE, ex.getMessage() + " enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); + server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex); } } } @@ -264,11 +264,13 @@ public final class SimplePluginManager implements PluginManager { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); - server.getScheduler().cancelTasks(plugin); - server.getServicesManager().unregisterAll(plugin); } catch (Throwable ex) { - server.getLogger().log(Level.SEVERE, ex.getMessage() + " disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); + server.getLogger().log(Level.SEVERE, "Error occurredd (in the plugin loader) while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex); } + + // Forced disable + server.getScheduler().cancelTasks(plugin); + server.getServicesManager().unregisterAll(plugin); } } diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index f38b7d1f5b..fa54be7215 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -673,7 +673,15 @@ public final class JavaPluginLoader implements PluginLoader { loaders.put(pluginName, (PluginClassLoader)jPlugin.getClassLoader()); } - jPlugin.setEnabled(true); + try { + jPlugin.setEnabled(true); + } catch (Throwable ex) { + server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex); + } + + // Perhaps abort here, rather than continue going, but as it stands, + // an abort is not possible the way it's currently written + server.getPluginManager().callEvent(new PluginEnableEvent(plugin)); } } @@ -687,7 +695,11 @@ public final class JavaPluginLoader implements PluginLoader { JavaPlugin jPlugin = (JavaPlugin)plugin; ClassLoader cloader = jPlugin.getClassLoader(); - jPlugin.setEnabled(false); + try { + jPlugin.setEnabled(false); + } catch (Throwable ex) { + server.getLogger().log(Level.SEVERE, "Error occurred while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex); + } server.getPluginManager().callEvent(new PluginDisableEvent(plugin));