Skip to content

Commit

Permalink
Create the option to search for a none MC Specific forge jar on the c…
Browse files Browse the repository at this point in the history
…lass path.
  • Loading branch information
marchermans committed Oct 12, 2023
1 parent 043de48 commit 06ce743
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -75,12 +76,16 @@ protected String[] preLaunch(String[] arguments, ModuleLayer layer) {

return args.getArguments();
}

protected static Optional<Path> searchJarOnClasspath(String[] classpath, String match) {
return Arrays.stream(classpath)
.filter(e -> FileUtils.matchFileName(e, false, match))
.findFirst().map(Paths::get);
}

protected static Path findJarOnClasspath(String[] classpath, String match) {
return Paths.get(Arrays.stream(classpath)
.filter(e -> FileUtils.matchFileName(e, false, match))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Could not find " + match + " in classpath")));
return searchJarOnClasspath(classpath, match)
.orElseThrow(() -> new IllegalStateException("Could not find " + match + " in classpath"));
}

protected BiPredicate<String, String> getMcFilter(Path extra, List<Path> minecraft, Stream.Builder<List<Path>> mods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
public abstract class ForgeUserdevLaunchHandler extends CommonUserdevLaunchHandler {
@Override
protected void processStreams(String[] classpath, VersionInfo versionInfo, Stream.Builder<Path> mc, Stream.Builder<List<Path>> mods) {
var forge = findJarOnClasspath(classpath, "forge-" + versionInfo.mcAndForgeVersion());
mc.add(forge);
var forge = searchJarOnClasspath(classpath, "forge-" + versionInfo.mcAndForgeVersion());
if (forge.isEmpty()) {
forge = searchJarOnClasspath(classpath, "forge-" + versionInfo.forgeVersion());
}
if (forge.isEmpty()) {
throw new RuntimeException("Could not find %s, nor %s jar on classpath".formatted("forge-" + versionInfo.mcAndForgeVersion(), "forge-" + versionInfo.forgeVersion()));
}
mc.add(forge.get());
}
}

0 comments on commit 06ce743

Please sign in to comment.