mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-06 02:31:46 +01:00
87 lines
3.2 KiB
Diff
87 lines
3.2 KiB
Diff
From 15a8f8edb2a5bca8b39560784ce8d20cb1f89d74 Mon Sep 17 00:00:00 2001
|
|
From: abhiram <abhithegamer2019@gmail.com>
|
|
Date: Thu, 13 May 2021 01:05:03 +0530
|
|
Subject: [PATCH] Added an api method to unload Plugins
|
|
|
|
Format Code to Bungee's code style
|
|
|
|
diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java
|
|
index 90031156..a190dfae 100644
|
|
--- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java
|
|
+++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java
|
|
@@ -25,6 +25,7 @@ import java.util.Set;
|
|
import java.util.Stack;
|
|
import java.util.jar.JarEntry;
|
|
import java.util.jar.JarFile;
|
|
+import java.util.logging.Handler;
|
|
import java.util.logging.Level;
|
|
import io.github.waterfallmc.waterfall.event.ProxyExceptionEvent; // Waterfall
|
|
import io.github.waterfallmc.waterfall.exception.ProxyCommandException; // Waterfall
|
|
@@ -63,6 +64,7 @@ public final class PluginManager
|
|
private Map<String, PluginDescription> toLoad = new HashMap<>();
|
|
private final Multimap<Plugin, Command> commandsByPlugin = ArrayListMultimap.create();
|
|
private final Multimap<Plugin, Listener> listenersByPlugin = ArrayListMultimap.create();
|
|
+ private final HashMap<String,URLClassLoader> pluginloaders = new HashMap<>();
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public PluginManager(ProxyServer proxy)
|
|
@@ -291,6 +293,45 @@ public final class PluginManager
|
|
return plugins.get( name );
|
|
}
|
|
|
|
+
|
|
+ /**
|
|
+ * This will Unload the given plugin
|
|
+ *
|
|
+ * @param plugin to unload
|
|
+ */
|
|
+ // FlameCord start - Adds a method to unload plugin from proxy
|
|
+ public void unloadPlugin(Plugin plugin)
|
|
+ {
|
|
+ plugin.onDisable();
|
|
+ this.unregisterListeners( plugin );
|
|
+ this.unregisterCommands( plugin );
|
|
+ this.proxy.getScheduler().cancel( plugin );
|
|
+
|
|
+ for ( Handler handler : plugin.getLogger().getHandlers() )
|
|
+ {
|
|
+ handler.close();
|
|
+ }
|
|
+
|
|
+ try
|
|
+ {
|
|
+ pluginloaders.get( plugin.getDescription().getName() ).close();
|
|
+ }catch (Exception exception)
|
|
+ {
|
|
+ exception.printStackTrace();
|
|
+ }
|
|
+
|
|
+ if( this.plugins.containsKey( plugin.getDescription().getName() ) )
|
|
+ {
|
|
+ this.plugins.remove( plugin.getDescription().getName() );
|
|
+ }
|
|
+
|
|
+ if( this.pluginloaders.containsKey( plugin.getDescription().getName() ) )
|
|
+ {
|
|
+ this.pluginloaders.remove( plugin.getDescription().getName() );
|
|
+ }
|
|
+ }
|
|
+ // FlameCord end
|
|
+
|
|
public void loadPlugins()
|
|
{
|
|
Map<PluginDescription, Boolean> pluginStatuses = new HashMap<>();
|
|
@@ -395,6 +436,9 @@ public final class PluginManager
|
|
Plugin clazz = (Plugin) main.getDeclaredConstructor().newInstance();
|
|
|
|
plugins.put( plugin.getName(), clazz );
|
|
+ // FlameCord start - cache url classloaders to unload plugins
|
|
+ pluginloaders.put( plugin.getName(),loader );
|
|
+ // FlameCord end
|
|
clazz.onLoad();
|
|
ProxyServer.getInstance().getLogger().log( Level.INFO, "Loaded plugin {0} version {1} by {2}", new Object[]
|
|
{
|
|
--
|
|
2.32.0
|
|
|