Skip to content

Commit 320bcea

Browse files
Trial97peterix
authored andcommitted
fix: noeforge
Signed-off-by: Trial97 <[email protected]> Signed-off-by: Petr Mrázek <[email protected]>
1 parent 4979cb0 commit 320bcea

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.net.URL;
44
import java.net.URISyntaxException;
5+
import java.net.MalformedURLException;
56
import java.nio.file.Path;
67
import java.nio.file.Paths;
78
import java.util.HashMap;
@@ -30,19 +31,24 @@ default Path getLibraryDir() {
3031
try {
3132
URL launcherLocation = null;
3233
String[] classNames = {
33-
"cpw.mods.modlauncher.Launcher",
34-
"net.neoforged.fml.loading.FMLLoader"
34+
"cpw/mods/modlauncher/Launcher.class",
35+
"net/neoforged/fml/loading/FMLLoader.class"
3536
};
3637

37-
for (String className : classNames) {
38-
try {
39-
Class<?> clazz = Class.forName(className);
40-
// Return the location of the loaded class
41-
if (clazz.getProtectionDomain().getCodeSource() != null) {
42-
launcherLocation = clazz.getProtectionDomain().getCodeSource().getLocation();
38+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
39+
for (String classResource : classNames) {
40+
URL url = cl.getResource(classResource);
41+
if (url != null) {
42+
String path = url.toString();
43+
if (path.startsWith("jar:") && path.contains("!")) {
44+
path = path.substring(4, path.indexOf('!'));
45+
try {
46+
launcherLocation = new URL(path);
47+
break;
48+
} catch (MalformedURLException e) {
49+
// ignore and try next
50+
}
4351
}
44-
} catch (ClassNotFoundException e) {
45-
// ignore and try next
4652
}
4753
}
4854

0 commit comments

Comments
 (0)