public void enablePlugin(final Plugin plugin) { if (!(plugin instanceof JavaPlugin)) { throw new IllegalArgumentException("Plugin is not associated with this PluginLoader"); } if (!plugin.isEnabled()) { JavaPlugin jPlugin = (JavaPlugin) plugin; String pluginName = jPlugin.getDescription().getName(); if (!loaders.containsKey(pluginName)) { loaders.put(pluginName, (PluginClassLoader) jPlugin.getClassLoader()); } 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)); } }
public void disablePlugin(Plugin plugin) { if (!(plugin instanceof JavaPlugin)) { throw new IllegalArgumentException("Plugin is not associated with this PluginLoader"); } if (plugin.isEnabled()) { JavaPlugin jPlugin = (JavaPlugin) plugin; ClassLoader cloader = jPlugin.getClassLoader(); 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)); loaders.remove(jPlugin.getDescription().getName()); if (cloader instanceof PluginClassLoader) { PluginClassLoader loader = (PluginClassLoader) cloader; Set<String> names = loader.getClasses(); for (String name : names) { removeClass(name); } } } }