Add dependency jdk 11 compat
This commit is contained in:
parent
c070f08071
commit
80208eef6e
@ -1,10 +1,12 @@
|
||||
package io.izzel.taboolib.module.dependency;
|
||||
|
||||
import io.izzel.taboolib.common.plugin.InternalPlugin;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
@ -13,11 +15,22 @@ import java.net.URLClassLoader;
|
||||
|
||||
public class TDependencyLoader {
|
||||
|
||||
private static final long ucpOffset;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field ucp = Bukkit.class.getClassLoader().getClass().getDeclaredField("ucp");
|
||||
ucpOffset = Ref.UNSAFE.objectFieldOffset(ucp);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void addToPath(Plugin plugin, URL url) {
|
||||
try {
|
||||
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin instanceof InternalPlugin ? Bukkit.class.getClassLoader() : plugin.getClass().getClassLoader(), url);
|
||||
Object ucp = Ref.UNSAFE.getObject(plugin instanceof InternalPlugin ? Bukkit.class.getClassLoader() : plugin.getClass().getClassLoader(), ucpOffset);
|
||||
Method addURL = ucp.getClass().getMethod("addURL", URL.class);
|
||||
addURL.invoke(ucp, url);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -34,9 +34,8 @@ public class Ref {
|
||||
try {
|
||||
return (Unsafe) io.izzel.taboolib.util.Reflection.getValue(null, Unsafe.class, true, "theUnsafe");
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
throw new IllegalStateException("Unsafe not found");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Field> getDeclaredFields(Class<?> clazz) {
|
||||
|
Loading…
Reference in New Issue
Block a user