Skip to content

Commit c66e72b

Browse files
committed
finally fix those 7 warnings
1 parent 85b3cb1 commit c66e72b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/main/java/com/falsepattern/lib/mixin/MinecraftURLClassPath.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22

33
import cpw.mods.fml.common.Loader;
44
import cpw.mods.fml.common.ModClassLoader;
5+
import lombok.AccessLevel;
6+
import lombok.NoArgsConstructor;
57
import lombok.val;
68
import net.minecraft.launchwrapper.LaunchClassLoader;
7-
import sun.misc.URLClassPath;
89

910
import 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)
1720
public 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

Comments
 (0)