22
33import cpw .mods .fml .common .Loader ;
44import cpw .mods .fml .common .ModClassLoader ;
5+ import lombok .AccessLevel ;
6+ import lombok .NoArgsConstructor ;
57import lombok .val ;
68import net .minecraft .launchwrapper .LaunchClassLoader ;
7- import sun .misc .URLClassPath ;
89
910import java .io .File ;
10- import java .lang .reflect .Field ;
11+ import java .lang .reflect .Method ;
12+ import java .net .URL ;
1113
1214/**
1315 * Backport from spongemixins 1.3 for compat with the curseforge 1.2.0 version.
1416 *
1517 * Also added Grimoire protection.
1618 */
19+ @ NoArgsConstructor (access = AccessLevel .PRIVATE )
1720public final class MinecraftURLClassPath {
1821 /**
1922 * Utility to manipulate the minecraft URL ClassPath
2023 */
2124
22- private static final URLClassPath ucp ;
25+ private static final Object ucp ;
26+ private static final Method addURL ;
2327 private static final boolean GRIMOIRE ;
2428
2529 static {
@@ -48,12 +52,14 @@ public final class MinecraftURLClassPath {
4852 Object loader = loaderinstanceField .get (null );
4953 val modClassLoader = (ModClassLoader ) modClassLoaderField .get (loader );
5054 val mainClassLoader = (LaunchClassLoader ) mainClassLoaderField .get (modClassLoader );
51- ucp = (URLClassPath ) ucpField .get (mainClassLoader );
52- } catch (NoSuchFieldException | IllegalAccessException e ) {
55+ ucp = ucpField .get (mainClassLoader );
56+ addURL = ucp .getClass ().getDeclaredMethod ("addURL" , URL .class );
57+ } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e ) {
5358 throw new RuntimeException (e .getMessage ());
5459 }
5560 } else {
5661 ucp = null ;
62+ addURL = null ;
5763 System .err .println ("Grimoire detected, disabling jar loading utility" );
5864 }
5965 }
@@ -64,11 +70,6 @@ public final class MinecraftURLClassPath {
6470 */
6571 public static void addJar (File pathToJar ) throws Exception {
6672 if (!GRIMOIRE )
67- ucp . addURL ( pathToJar .toURI ().toURL ());
73+ addURL . invoke ( ucp , pathToJar .toURI ().toURL ());
6874 }
69-
70- private MinecraftURLClassPath () {
71- }
72-
73-
7475}
0 commit comments