Merge pull request #38 from Luohuayu/patch-1
Implement load dependency in LaunchClassLoader
This commit is contained in:
commit
a94f328fb2
@ -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();
|
||||||
Field ucpField = loader.getClass().getDeclaredField("ucp");
|
if ("LaunchClassLoader".equals(loader.getClass().getSimpleName())) {
|
||||||
long ucpOffset = Ref.getUnsafe().objectFieldOffset(ucpField);
|
MethodHandle methodHandle = Ref.lookup().findVirtual(loader.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class));
|
||||||
Object ucp = Ref.getUnsafe().getObject(loader, ucpOffset);
|
methodHandle.invoke(loader, url);
|
||||||
MethodHandle methodHandle = Ref.lookup().findVirtual(ucp.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class));
|
} else {
|
||||||
methodHandle.invoke(ucp, url);
|
Field ucpField = loader.getClass().getDeclaredField("ucp");
|
||||||
|
long ucpOffset = Ref.getUnsafe().objectFieldOffset(ucpField);
|
||||||
|
Object ucp = Ref.getUnsafe().getObject(loader, ucpOffset);
|
||||||
|
MethodHandle methodHandle = Ref.lookup().findVirtual(ucp.getClass(), "addURL", MethodType.methodType(void.class, java.net.URL.class));
|
||||||
|
methodHandle.invoke(ucp, url);
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user