Skip to content

Commit df9f52d

Browse files
committed
More robust jar detection for mixins
1 parent 7994dbe commit df9f52d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
import java.io.File;
3535
import java.io.FileNotFoundException;
36-
import java.io.IOException;
36+
import java.net.URL;
3737
import java.nio.file.Path;
38+
import java.nio.file.Paths;
3839
import java.util.ArrayList;
3940
import java.util.Arrays;
4041
import java.util.List;
@@ -55,12 +56,29 @@ static Logger createLogger(String modName) {
5556

5657
@StableAPI.Expose
5758
static File findJarOf(final ITargetedMod mod) {
59+
File result = null;
5860
try (val stream = walk(MODS_DIRECTORY_PATH)) {
59-
return stream.filter(mod::isMatchingJar).map(Path::toFile).findFirst().orElse(null);
60-
} catch (IOException e) {
61+
result = stream.filter(mod::isMatchingJar)
62+
.map(Path::toFile)
63+
.findFirst()
64+
.orElse(null);
65+
} catch (Exception e) {
6166
e.printStackTrace();
62-
return null;
6367
}
68+
if (result == null) {
69+
try {
70+
result = Arrays.stream(Launch.classLoader.getURLs())
71+
.map(URL::getPath)
72+
.map(Paths::get)
73+
.filter(mod::isMatchingJar)
74+
.map(Path::toFile)
75+
.findFirst()
76+
.orElse(null);
77+
} catch (Exception e) {
78+
e.printStackTrace();
79+
}
80+
}
81+
return result;
6482
}
6583

6684
@StableAPI.Expose

0 commit comments

Comments
 (0)