From 7f3072128f37d6c3c074885d149bd305f75d8365 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Mon, 25 Jul 2022 22:31:45 +0800 Subject: [PATCH] Download MOJMAPS in installer --- .../forgeinstaller/ForgeInstaller.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/forge-installer/src/main/java/io/izzel/arclight/forgeinstaller/ForgeInstaller.java b/forge-installer/src/main/java/io/izzel/arclight/forgeinstaller/ForgeInstaller.java index beae34a2..f0fc6ddf 100644 --- a/forge-installer/src/main/java/io/izzel/arclight/forgeinstaller/ForgeInstaller.java +++ b/forge-installer/src/main/java/io/izzel/arclight/forgeinstaller/ForgeInstaller.java @@ -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 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 VERSION_HASH = Map.of( "1.18.2", "c8f83c5655308435b3dcf03c06d9fe8740a77469" ); + private static final Map MAPPING_HASH = Map.of( + "1.18.2", "e562f588fea155d96291267465dc3323bfe1551b" + ); public static List modInstall(Consumer logger) throws Throwable { InputStream stream = ForgeInstaller.class.getModule().getResourceAsStream("/META-INF/installer.json"); @@ -131,9 +135,9 @@ public class ForgeInstaller { FileSystem system = FileSystems.newFileSystem(path, (ClassLoader) null); Map> map = new HashMap<>(); Path profile = system.getPath("install_profile.json"); - map.putAll(profileLibraries(profile)); + map.putAll(profileLibraries(profile, info.installer.minecraft)); Path version = system.getPath("version.json"); - map.putAll(profileLibraries(version)); + map.putAll(profileLibraries(version, info.installer.minecraft)); List> suppliers = checkMaven(map); CompletableFuture[] array = suppliers.stream().map(reportSupply(pool, logger)).toArray(CompletableFuture[]::new); handleFutures(logger, array); @@ -162,9 +166,10 @@ public class ForgeInstaller { } } - private static Map> profileLibraries(Path path) throws IOException { + private static Map> profileLibraries(Path path, String minecraft) throws IOException { Map> 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) { String name = element.getAsJsonObject().get("name").getAsString(); JsonObject artifact = element.getAsJsonObject().getAsJsonObject("downloads").getAsJsonObject("artifact"); @@ -173,6 +178,14 @@ public class ForgeInstaller { if (url == null || url.trim().isEmpty()) continue; 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; }