Set libraryLoader to null & clear classes in PluginClassLoader (bukkit)
This commit is contained in:
parent
870e2bcae5
commit
fd69f74b22
5 changed files with 23 additions and 18 deletions
|
|
@ -146,12 +146,11 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPlu
|
||||||
RSimplePluginManager.removeLookupName(Bukkit.getPluginManager(), pluginId);
|
RSimplePluginManager.removeLookupName(Bukkit.getPluginManager(), pluginId);
|
||||||
|
|
||||||
ClassLoader classLoader = plugin.getClass().getClassLoader();
|
ClassLoader classLoader = plugin.getClass().getClassLoader();
|
||||||
RPluginClassLoader.clearClassLoader(classLoader);
|
|
||||||
|
|
||||||
PluginLoader loader = RPluginClassLoader.getLoader(classLoader);
|
PluginLoader loader = RPluginClassLoader.getLoader(classLoader);
|
||||||
Map<String, Class<?>> classes = RPluginClassLoader.getClasses(classLoader);
|
Map<String, Class<?>> classes = RPluginClassLoader.getClasses(classLoader);
|
||||||
RJavaPluginLoader.removeClasses(loader, classes.keySet());
|
RJavaPluginLoader.removeClasses(loader, classes.keySet());
|
||||||
|
|
||||||
|
RPluginClassLoader.clearClassLoader(classLoader);
|
||||||
RJavaPlugin.clearJavaPlugin(plugin);
|
RJavaPlugin.clearJavaPlugin(plugin);
|
||||||
|
|
||||||
addIfInstance(closeables, RPluginClassLoader.getLibraryLoader(classLoader));
|
addIfInstance(closeables, RPluginClassLoader.getLibraryLoader(classLoader));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
|
@ -23,12 +22,9 @@ public class RJavaPlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the JavaPlugin from instances and returns the classloader associated with it.
|
* Clears the JavaPlugin from instances and returns the classloader associated with it.
|
||||||
* @param instance The instance of the JavaPlugin.
|
|
||||||
* @return The classloader associated with it.
|
|
||||||
*/
|
*/
|
||||||
public static Closeable clearJavaPlugin(Object instance) {
|
public static void clearJavaPlugin(Object instance) {
|
||||||
reflection.set(instance, "loader", null);
|
reflection.set(instance, "loader", null);
|
||||||
reflection.set(instance, "classLoader", null);
|
reflection.set(instance, "classLoader", null);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||||
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
|
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
|
||||||
import java.util.Map;
|
import dev.frankheijden.minecraftreflection.Reflection;
|
||||||
|
import net.frankheijden.serverutils.common.utils.ReflectionUtils;
|
||||||
import org.bukkit.plugin.PluginLoader;
|
import org.bukkit.plugin.PluginLoader;
|
||||||
|
|
||||||
public class RPluginClassLoader {
|
public class RPluginClassLoader {
|
||||||
|
|
@ -31,22 +34,29 @@ public class RPluginClassLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClassLoader getLibraryLoader(ClassLoader loader) {
|
public static ClassLoader getLibraryLoader(ClassLoader loader) {
|
||||||
if (loader == null && MinecraftReflectionVersion.MINOR <= 16) return null;
|
if (loader == null || MinecraftReflectionVersion.MINOR <= 16) return null;
|
||||||
return reflection.get(loader, "libraryLoader");
|
return reflection.get(loader, "libraryLoader");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the plugin fields from the specified PluginClassLoader.
|
* Clears the plugin fields from the specified PluginClassLoader.
|
||||||
* @param pluginLoader The plugin loader instance.
|
|
||||||
*/
|
*/
|
||||||
public static void clearPluginClassLoader(Object pluginLoader) {
|
public static void clearPluginClassLoader(Object classLoader) {
|
||||||
if (pluginLoader == null) return;
|
if (classLoader == null) return;
|
||||||
|
|
||||||
reflection.set(pluginLoader, "plugin", null);
|
reflection.set(classLoader, "loader", null);
|
||||||
reflection.set(pluginLoader, "pluginInit", null);
|
if (MinecraftReflectionVersion.MINOR > 16) {
|
||||||
|
ReflectionUtils.doPrivilegedWithUnsafe(unsafe -> {
|
||||||
|
Field libraryLoaderField = Reflection.getField(reflection.getClazz(), "libraryLoader");
|
||||||
|
unsafe.putObject(classLoader, unsafe.objectFieldOffset(libraryLoaderField), null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
reflection.set(classLoader, "plugin", null);
|
||||||
|
reflection.set(classLoader, "pluginInit", null);
|
||||||
|
getClasses(classLoader).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Class<?>> getClasses(Object pluginLoader) {
|
public static Map<String, Class<?>> getClasses(Object classLoader) {
|
||||||
return reflection.get(pluginLoader, "classes");
|
return reflection.get(classLoader, "classes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package net.frankheijden.serverutils.velocity.utils;
|
package net.frankheijden.serverutils.common.utils;
|
||||||
|
|
||||||
import dev.frankheijden.minecraftreflection.Reflection;
|
import dev.frankheijden.minecraftreflection.Reflection;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
|
@ -15,8 +15,8 @@ import java.lang.reflect.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import net.frankheijden.serverutils.common.utils.ReflectionUtils;
|
||||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||||
import net.frankheijden.serverutils.velocity.utils.ReflectionUtils;
|
|
||||||
|
|
||||||
public class RVelocityCommandManager {
|
public class RVelocityCommandManager {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue