2
2
3
3
import cpw .mods .fml .common .Loader ;
4
4
import cpw .mods .fml .common .ModClassLoader ;
5
+ import lombok .AccessLevel ;
6
+ import lombok .NoArgsConstructor ;
5
7
import lombok .val ;
6
8
import net .minecraft .launchwrapper .LaunchClassLoader ;
7
- import sun .misc .URLClassPath ;
8
9
9
10
import java .io .File ;
10
- import java .lang .reflect .Field ;
11
+ import java .lang .reflect .Method ;
12
+ import java .net .URL ;
11
13
12
14
/**
13
15
* Backport from spongemixins 1.3 for compat with the curseforge 1.2.0 version.
14
16
*
15
17
* Also added Grimoire protection.
16
18
*/
19
+ @ NoArgsConstructor (access = AccessLevel .PRIVATE )
17
20
public final class MinecraftURLClassPath {
18
21
/**
19
22
* Utility to manipulate the minecraft URL ClassPath
20
23
*/
21
24
22
- private static final URLClassPath ucp ;
25
+ private static final Object ucp ;
26
+ private static final Method addURL ;
23
27
private static final boolean GRIMOIRE ;
24
28
25
29
static {
@@ -48,12 +52,14 @@ public final class MinecraftURLClassPath {
48
52
Object loader = loaderinstanceField .get (null );
49
53
val modClassLoader = (ModClassLoader ) modClassLoaderField .get (loader );
50
54
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 ) {
53
58
throw new RuntimeException (e .getMessage ());
54
59
}
55
60
} else {
56
61
ucp = null ;
62
+ addURL = null ;
57
63
System .err .println ("Grimoire detected, disabling jar loading utility" );
58
64
}
59
65
}
@@ -64,11 +70,6 @@ public final class MinecraftURLClassPath {
64
70
*/
65
71
public static void addJar (File pathToJar ) throws Exception {
66
72
if (!GRIMOIRE )
67
- ucp . addURL ( pathToJar .toURI ().toURL ());
73
+ addURL . invoke ( ucp , pathToJar .toURI ().toURL ());
68
74
}
69
-
70
- private MinecraftURLClassPath () {
71
- }
72
-
73
-
74
75
}
0 commit comments