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 f0d1759 commit d100adc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -44,8 +43,6 @@

public class ForgeInstaller {

private static final MethodHandles.Lookup IMPL_LOOKUP = Unsafe.lookup();

public static List<Path> modInstall(Consumer<String> logger) throws Throwable {
InputStream stream = ForgeInstaller.class.getModule().getResourceAsStream("/META-INF/installer.json");
InstallInfo installInfo = new Gson().fromJson(new InputStreamReader(stream), InstallInfo.class);
Expand Down Expand Up @@ -166,7 +163,7 @@ private static CompletableFuture<Path>[] installForge(InstallInfo info, Executor
});
var serverFuture = minecraftData.thenCompose(data -> reportSupply(pool, logger).apply(
new FileDownloader(String.format(data.serverUrl, info.installer.minecraft),
String.format("libraries/net/minecraft/server/%1$s/server-%1$s.jar", info.installer.minecraft), data.serverHash)
String.format("libraries/net/minecraft/server/%1$s/server-%1$s-bundled.jar", info.installer.minecraft), data.serverHash)
));
return new CompletableFuture[]{installerFuture, serverFuture};
}
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 d100adc

Please sign in to comment.