Download MOJMAPS in installer

This commit is contained in:
IzzelAliz 2022-07-25 22:31:45 +08:00
parent 0d943311fc
commit 7f3072128f
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338

View File

@ -57,9 +57,13 @@ public class ForgeInstaller {
}; };
private static final String INSTALLER_URL = "https://arclight.mcxk.net/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar"; private static final String INSTALLER_URL = "https://arclight.mcxk.net/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar";
private static final String SERVER_URL = "https://arclight.mcxk.net/net/minecraft/server/minecraft_server.%s.jar"; private static final String SERVER_URL = "https://arclight.mcxk.net/net/minecraft/server/minecraft_server.%s.jar";
private static final String MAPPING_URL = "https://arclight.mcxk.net/net/minecraft/server/mappings_server.%s.txt";
private static final Map<String, String> VERSION_HASH = Map.of( private static final Map<String, String> VERSION_HASH = Map.of(
"1.18.2", "c8f83c5655308435b3dcf03c06d9fe8740a77469" "1.18.2", "c8f83c5655308435b3dcf03c06d9fe8740a77469"
); );
private static final Map<String, String> MAPPING_HASH = Map.of(
"1.18.2", "e562f588fea155d96291267465dc3323bfe1551b"
);
public static List<Path> modInstall(Consumer<String> logger) throws Throwable { public static List<Path> modInstall(Consumer<String> logger) throws Throwable {
InputStream stream = ForgeInstaller.class.getModule().getResourceAsStream("/META-INF/installer.json"); InputStream stream = ForgeInstaller.class.getModule().getResourceAsStream("/META-INF/installer.json");
@ -131,9 +135,9 @@ public class ForgeInstaller {
FileSystem system = FileSystems.newFileSystem(path, (ClassLoader) null); FileSystem system = FileSystems.newFileSystem(path, (ClassLoader) null);
Map<String, Map.Entry<String, String>> map = new HashMap<>(); Map<String, Map.Entry<String, String>> map = new HashMap<>();
Path profile = system.getPath("install_profile.json"); Path profile = system.getPath("install_profile.json");
map.putAll(profileLibraries(profile)); map.putAll(profileLibraries(profile, info.installer.minecraft));
Path version = system.getPath("version.json"); Path version = system.getPath("version.json");
map.putAll(profileLibraries(version)); map.putAll(profileLibraries(version, info.installer.minecraft));
List<Supplier<Path>> suppliers = checkMaven(map); List<Supplier<Path>> suppliers = checkMaven(map);
CompletableFuture<?>[] array = suppliers.stream().map(reportSupply(pool, logger)).toArray(CompletableFuture[]::new); CompletableFuture<?>[] array = suppliers.stream().map(reportSupply(pool, logger)).toArray(CompletableFuture[]::new);
handleFutures(logger, array); handleFutures(logger, array);
@ -162,9 +166,10 @@ public class ForgeInstaller {
} }
} }
private static Map<String, Map.Entry<String, String>> profileLibraries(Path path) throws IOException { private static Map<String, Map.Entry<String, String>> profileLibraries(Path path, String minecraft) throws IOException {
Map<String, Map.Entry<String, String>> ret = new HashMap<>(); Map<String, Map.Entry<String, String>> ret = new HashMap<>();
JsonArray array = new JsonParser().parse(Files.newBufferedReader(path)).getAsJsonObject().getAsJsonArray("libraries"); var object = new JsonParser().parse(Files.newBufferedReader(path)).getAsJsonObject();
JsonArray array = object.getAsJsonArray("libraries");
for (JsonElement element : array) { for (JsonElement element : array) {
String name = element.getAsJsonObject().get("name").getAsString(); String name = element.getAsJsonObject().get("name").getAsString();
JsonObject artifact = element.getAsJsonObject().getAsJsonObject("downloads").getAsJsonObject("artifact"); JsonObject artifact = element.getAsJsonObject().getAsJsonObject("downloads").getAsJsonObject("artifact");
@ -173,6 +178,14 @@ public class ForgeInstaller {
if (url == null || url.trim().isEmpty()) continue; if (url == null || url.trim().isEmpty()) continue;
ret.put(name, new AbstractMap.SimpleImmutableEntry<>(hash, url)); ret.put(name, new AbstractMap.SimpleImmutableEntry<>(hash, url));
} }
if (object.has("data")) {
var data = object.getAsJsonObject("data");
if (data.has("MOJMAPS")) {
var serverMapping = data.getAsJsonObject("MOJMAPS").get("server").getAsString();
ret.put(serverMapping.substring(1, serverMapping.length() -1),
new AbstractMap.SimpleImmutableEntry<>(MAPPING_HASH.get(minecraft), MAPPING_URL.formatted(minecraft)));
}
}
return ret; return ret;
} }