Merge remote-tracking branch 'origin/master'

This commit is contained in:
sky 2020-02-18 14:46:04 +08:00
commit 98251ec4aa

View File

@ -20,11 +20,16 @@ public class TDependencyLoader {
public static synchronized void addToPath(Plugin plugin, URL url) { public static synchronized void addToPath(Plugin plugin, URL url) {
try { try {
ClassLoader loader = plugin instanceof InternalPlugin ? Bukkit.class.getClassLoader() : plugin.getClass().getClassLoader(); ClassLoader loader = plugin instanceof InternalPlugin ? Bukkit.class.getClassLoader() : plugin.getClass().getClassLoader();
if ("LaunchClassLoader".equals(loader.getClass().getSimpleName())) {
MethodHandle methodHandle = Ref.lookup().findVirtual(loader.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class));
methodHandle.invoke(loader, url);
} else {
Field ucpField = loader.getClass().getDeclaredField("ucp"); Field ucpField = loader.getClass().getDeclaredField("ucp");
long ucpOffset = Ref.getUnsafe().objectFieldOffset(ucpField); long ucpOffset = Ref.getUnsafe().objectFieldOffset(ucpField);
Object ucp = Ref.getUnsafe().getObject(loader, ucpOffset); Object ucp = Ref.getUnsafe().getObject(loader, ucpOffset);
MethodHandle methodHandle = Ref.lookup().findVirtual(ucp.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class)); MethodHandle methodHandle = Ref.lookup().findVirtual(ucp.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class));
methodHandle.invoke(ucp, url); methodHandle.invoke(ucp, url);
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }