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
|
|
@ -0,0 +1,41 @@
|
|||
package net.frankheijden.serverutils.common.utils;
|
||||
|
||||
import dev.frankheijden.minecraftreflection.Reflection;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.function.Consumer;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
public class ReflectionUtils {
|
||||
|
||||
private static MethodHandle theUnsafeFieldMethodHandle;
|
||||
|
||||
static {
|
||||
try {
|
||||
theUnsafeFieldMethodHandle = MethodHandles.lookup().unreflectGetter(Reflection.getAccessibleField(
|
||||
Unsafe.class,
|
||||
"theUnsafe"
|
||||
));
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private ReflectionUtils() {}
|
||||
|
||||
/**
|
||||
* Performs a privileged action while accessing {@link Unsafe}.
|
||||
*/
|
||||
public static void doPrivilegedWithUnsafe(Consumer<Unsafe> privilegedAction) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
try {
|
||||
privilegedAction.accept((Unsafe) theUnsafeFieldMethodHandle.invoke());
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue