Skip to content

Commit

Permalink
Provide fallback install when java not in path (#179 #209)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Apr 18, 2021
1 parent 5f82080 commit 2f13fc4
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down Expand Up @@ -65,11 +66,19 @@ public static void install() throws Throwable {
CompletableFuture<?>[] futures = installForge(installInfo, pool);
handleFutures(futures);
ArclightLocale.info("downloader.forge-install");
ProcessBuilder builder = new ProcessBuilder();
builder.command("java", "-Djava.net.useSystemProxies=true", "-jar", String.format("forge-%s-%s-installer.jar", installInfo.installer.minecraft, installInfo.installer.forge), "--installServer", ".");
builder.inheritIO();
Process process = builder.start();
process.waitFor();
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command("java", "-Djava.net.useSystemProxies=true", "-jar", String.format("forge-%s-%s-installer.jar", installInfo.installer.minecraft, installInfo.installer.forge), "--installServer", ".");
builder.inheritIO();
Process process = builder.start();
process.waitFor();
} catch (IOException e) {
URLClassLoader loader = new URLClassLoader(
new URL[]{new File(String.format("forge-%s-%s-installer.jar", installInfo.installer.minecraft, installInfo.installer.forge)).toURI().toURL()},
ForgeInstaller.class.getClassLoader().getParent());
Method method = loader.loadClass("net.minecraftforge.installer.SimpleInstaller").getMethod("main", String[].class);
method.invoke(null, (Object) new String[]{"--installServer", "."});
}
}
handleFutures(array);
pool.shutdownNow();
Expand Down

0 comments on commit 2f13fc4

Please sign in to comment.