Update download mirrors (#1200)

This commit is contained in:
IzzelAliz 2024-01-26 20:54:00 +08:00
parent 033f7507e6
commit 976e874c78
3 changed files with 13 additions and 11 deletions

View File

@ -92,7 +92,9 @@ public class ForgeInstaller {
builder.command(file.getCanonicalPath(), "-Djava.net.useSystemProxies=true", "-jar", futures[0].join().toString(), "--installServer", ".", "--debug");
builder.inheritIO();
Process process = builder.start();
process.waitFor();
if (process.waitFor() > 0) {
throw new Exception("Forge installation failed");
}
} catch (IOException e) {
try (URLClassLoader loader = new URLClassLoader(
new URL[]{new File(String.format("forge-%s-%s-installer.jar", installInfo.installer.minecraft, installInfo.installer.forge)).toURI().toURL()},

View File

@ -5,15 +5,10 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.function.Supplier;
public class MavenDownloader implements Supplier<Path> {
private static final Function<String, String> FORGE_TO_BMCLAPI =
s -> s.replace("https://files.minecraftforge.net/maven/", "https://download.mcbbs.net/maven/")
.replace("https://maven.minecraftforge.net/", "https://download.mcbbs.net/maven/");
private final LinkedList<String> urls;
private final String coord;
private final String target;
@ -33,8 +28,11 @@ public class MavenDownloader implements Supplier<Path> {
public MavenDownloader(String[] repos, String coord, String target, String hash, String sourceUrl) {
this(repos, coord, target, hash);
if (sourceUrl != null && !this.urls.contains(sourceUrl)) {
this.urls.addFirst(sourceUrl);
this.urls.addFirst(FORGE_TO_BMCLAPI.apply(sourceUrl));
if (Mirrors.isMirrorUrl(sourceUrl)) {
this.urls.addFirst(sourceUrl);
} else {
this.urls.addLast(sourceUrl);
}
}
}

View File

@ -9,13 +9,11 @@ public class Mirrors {
private static final String[] MAVEN_REPO = {
"https://arclight.hypertention.cn/",
"https://download.mcbbs.net/maven/",
"https://repo.spongepowered.org/maven/"
};
private static final String[] MOJANG_MIRROR = {
"https://download.mcbbs.net",
"https://bmclapi2.bangbang93.com",
"https://mojmirror.hypertention.cn",
"https://piston-meta.mojang.com"
};
@ -39,4 +37,8 @@ public class Mirrors {
.replace("https://piston-meta.mojang.com", mirror)
.replace("https://piston-data.mojang.com", mirror);
}
public static boolean isMirrorUrl(String url) {
return url.startsWith(MOJANG_MIRROR[0]);
}
}