Skip to content

Commit

Permalink
Update download mirrors (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Jan 26, 2024
1 parent 600f108 commit 6774479
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public static Map.Entry<String, List<String>> applicationInstall() throws Throwa
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()},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
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;
Expand All @@ -33,8 +28,11 @@ public MavenDownloader(String[] repos, String coord, String target, String hash)
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

Expand All @@ -39,4 +37,8 @@ public static String mapMojangMirror(String url, String mirror) {
.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]);
}
}

0 comments on commit 6774479

Please sign in to comment.