From d18bd7bff9dc87d5c8348a14c1634802f286a794 Mon Sep 17 00:00:00 2001 From: Space Walker Date: Wed, 15 Oct 2025 15:41:04 +0200 Subject: [PATCH 1/4] add support for gen2 OSL --- .../java/net/ornithemc/ploceus/Constants.java | 16 +- .../ornithemc/ploceus/OslVersionCache.java | 407 ++++++++++++------ .../ploceus/PloceusGradleExtension.java | 10 +- 3 files changed, 284 insertions(+), 149 deletions(-) diff --git a/src/main/java/net/ornithemc/ploceus/Constants.java b/src/main/java/net/ornithemc/ploceus/Constants.java index 8e3edb1..98431e3 100644 --- a/src/main/java/net/ornithemc/ploceus/Constants.java +++ b/src/main/java/net/ornithemc/ploceus/Constants.java @@ -95,11 +95,21 @@ public static String nests(String mc, GameSide side, String build) { public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF"; public static final String CALAMUS_GENERATION_ATTRIBUTE = "Calamus-Generation"; - public static final String OSL_MAVEN_GROUP = MAVEN_GROUP + ".osl"; + public static final String OSL_MAVEN_GROUP_GEN1 = MAVEN_GROUP + ".osl"; + public static final String OSL_MAVEN_GROUP_GEN2 = MAVEN_GROUP + ".osl-gen%d"; + public static String oslMavenGroup(int generation) { + return generation == 1 ? OSL_MAVEN_GROUP_GEN1 : String.format(OSL_MAVEN_GROUP_GEN2, generation); + } public static final String OSL_CORE = "core"; - public static final String OSL_META_ENDPOINT = "/v3/versions/osl/%s"; - public static final String OSL_MODULE_META_ENDPOINT = "/v3/versions/osl/%s/%s/%s"; + public static final String OSL_VERSION_META_ENDPOINT = "/v3/versions/gen%d/osl/%s"; + public static String oslVersionMetaEndpoint(int generation, String version) { + return String.format(OSL_VERSION_META_ENDPOINT, generation, version); + } + public static final String OSL_MODULE_VERSION_META_ENDPOINT = "/v3/versions/gen%d/osl/%s/%s/%s"; + public static String oslModuleVersionMetaEndpoint(int generation, String module, String mc, String version) { + return String.format(OSL_MODULE_VERSION_META_ENDPOINT, generation, module, mc, version); + } public static final String MCP_MAVEN_GROUP = "de.oceanlabs.mcp"; public static final String SRG_MAPPINGS = MCP_MAVEN_GROUP + ":mcp:%s:srg@zip"; diff --git a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java index 8bbe81e..8a2677f 100644 --- a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java +++ b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java @@ -2,14 +2,13 @@ import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.FileReader; -import java.io.FileWriter; import java.io.InputStreamReader; -import java.net.URL; +import java.net.URI; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import org.gradle.api.Project; @@ -30,205 +29,331 @@ public class OslVersionCache { private final Project project; private final PloceusGradleExtension ploceus; - private final Map> dependencies; - private final Map versions; - private final Path oslVersionCache; - private final Map oslModuleVersionCache; + private final Map> moduleBaseVersions; + private final Map moduleVersions; - private String mcVersion; + private Integer intermediaryGeneration; + private String minecraftVersion; + private Path moduleBaseVersionsCache; + private Path moduleVersionsCache; public OslVersionCache(Project project, PloceusGradleExtension ploceus) { - LoomGradleExtension loom = LoomGradleExtension.get(project); - Path userCache = loom.getFiles().getUserCache().toPath(); - this.project = project; this.ploceus = ploceus; - this.dependencies = new HashMap<>(); - this.versions = new HashMap<>(); - this.oslVersionCache = userCache.resolve("osl-versions.json"); - this.oslModuleVersionCache = new HashMap<>(); + this.moduleBaseVersions = new HashMap<>(); + this.moduleVersions = new HashMap<>(); } - private String mcVersion() { - if (mcVersion == null) { - mcVersion = ploceus.minecraftVersion(); + private int intermediaryGeneration() { + if (intermediaryGeneration == null) { + intermediaryGeneration = ploceus.getIntermediaryGeneration().get(); } - return mcVersion; + return intermediaryGeneration; } - public Map getDependencies(String version) throws Exception { - Map modules = dependencies.get(version); - - if (modules != null) { - return Collections.unmodifiableMap(modules); + private String minecraftVersion() { + if (minecraftVersion == null) { + minecraftVersion = ploceus.minecraftVersion(); } - modules = new HashMap<>(); - JsonArray modulesJson = queryOslModules(version); + return minecraftVersion; + } + + private Path moduleBaseVersionsCache() { + if (moduleBaseVersionsCache == null) { + LoomGradleExtension loom = LoomGradleExtension.get(project); + Path userCache = loom.getFiles().getUserCache().toPath(); + + moduleBaseVersionsCache = userCache.resolve("osl-versions.json"); + } - for (JsonElement moduleJson : modulesJson) { - JsonObject moduleJsonObj = moduleJson.getAsJsonObject(); - String maven = moduleJsonObj.get("maven").getAsString(); - String moduleName = maven.split("[:]")[1]; - String moduleVersion = moduleJsonObj.get("version").getAsString(); + return moduleBaseVersionsCache; + } - modules.put(moduleName, moduleVersion); + private Path moduleVersionsCache() { + if (moduleVersionsCache == null) { + LoomGradleExtension loom = LoomGradleExtension.get(project); + Path userCache = loom.getFiles().getUserCache().toPath(); + + moduleVersionsCache = userCache.resolve(minecraftVersion()).resolve("osl-module-versions.json"); } - // add this entry to the map only after the meta queries - // if they fail, we might add an empty map which is invalid - if (modules.isEmpty()) { - throw new RuntimeException("no OSL modules found for OSL " + version); - } else { - dependencies.put(version, modules); + return moduleVersionsCache; + } + + public Map getOslModuleBaseVersions(String version) { + Map modules = moduleBaseVersions.get(version); + + if (modules == null) { + moduleBaseVersions.put(version, modules = getModuleBaseVersions(version)); } - return Collections.unmodifiableMap(modules); + return modules; } - public String getDependency(String version, String module) throws Exception { - return getDependencies(version).get(module); + public String getOslModuleBaseVersion(String version, String module) { + return getOslModuleBaseVersions(version).get(module); } - /** - * checks if the osl version cache contains the specified version - * and queries the meta server for this data if needed - * - * @return the json array with the maven data for all the modules - * for this osl version - */ - private JsonArray queryOslModules(String version) throws Exception { - JsonObject json = null; + private Map getModuleBaseVersions(String version) { + Map baseVersions = null; - // if the file does not exist, we create it - // and we cache the json object so we do not - // unnecessarily read the file for that again - if (!Files.exists(oslVersionCache)) { - json = new JsonObject(); + try { + baseVersions = getModuleBaseVersionsFromMeta(version); + } catch (Exception me) { + try { + baseVersions = getModuleBaseVersionsFromCache(version); + } catch (Exception ce) { + project.getLogger().warn("unable to read OSL module base versions from cache for gen" + intermediaryGeneration() + " " + version, ce); + } - // no need to write this to disk at this point - // the data is empty so the meta will be queried - // and once the data has been added the file will - // be written to disk - } - if (json == null) { - try (BufferedReader br = new BufferedReader(new FileReader(oslVersionCache.toFile()))) { - json = GSON.fromJson(br, JsonObject.class); + if (baseVersions == null) { + throw new IllegalStateException("unable to fetch OSL module base versions from meta for gen" + intermediaryGeneration() + " " + version + ", and it is not in the cache", me); } } - JsonArray modulesJson = json.getAsJsonArray(version); + return baseVersions; + } - if (modulesJson == null) { - String metaUrl = String.format(Constants.META_URL + Constants.OSL_META_ENDPOINT, version); + private Map getModuleBaseVersionsFromMeta(String version) throws Exception { + String metaUrl = Constants.oslVersionMetaEndpoint(intermediaryGeneration(), version); + + try (InputStreamReader ir = new InputStreamReader(new URI(metaUrl).toURL().openStream())) { + JsonArray modulesJson = GSON.fromJson(ir, JsonArray.class); + Map baseVersions = new LinkedHashMap<>(); - try (InputStreamReader ir = new InputStreamReader(new URL(metaUrl).openStream())) { - modulesJson = GSON.fromJson(ir, JsonArray.class); - json.add(version, modulesJson); + for (JsonElement e : modulesJson) { + if (!e.isJsonObject()) { + continue; + } + + JsonObject moduleJson = e.getAsJsonObject(); + String maven = moduleJson.get("maven").getAsString(); + String moduleName = maven.split("[:]")[1]; + String moduleVersion = moduleJson.get("version").getAsString(); + + baseVersions.put(moduleName, moduleVersion); } - Files.createDirectories(oslVersionCache.getParent()); - try (BufferedWriter bw = new BufferedWriter(new FileWriter(oslVersionCache.toFile()))) { - GSON.toJson(json, bw); + + try { + saveModuleBaseVersionsToCache(version, baseVersions); + } catch (Exception e) { + project.getLogger().warn("unable to save OSL module base versions for gen" + intermediaryGeneration() + " " + version + " to cache", e); } - } - return modulesJson; + return baseVersions; + } } - public String getVersion(String module, String version, GameSide side) throws Exception { - String key = module + version; - String cachedVersion = versions.get(key); + private Map getModuleBaseVersionsFromCache(String version) throws Exception { + Path baseVersionsCache = moduleBaseVersionsCache(); + JsonObject json; - if (cachedVersion != null) { - return cachedVersion; + try (BufferedReader br = Files.newBufferedReader(baseVersionsCache)) { + json = GSON.fromJson(br, JsonObject.class); + } catch (NoSuchFileException e) { + return null; } - JsonArray versionsJson = queryOslModuleVersions(module, version, side); + String generation = "gen" + intermediaryGeneration(); + JsonObject versionsJson = json.getAsJsonObject(generation); + + if (versionsJson == null) { + return null; + } - for (JsonElement versionJson : versionsJson) { - JsonObject versionJsonObj = versionJson.getAsJsonObject(); - String moduleVersion = versionJsonObj.get("version").getAsString(); + JsonObject baseVersionsJson = versionsJson.getAsJsonObject(version); - if (side == GameSide.MERGED || module.equals(Constants.OSL_CORE) || moduleVersion.contains(side.id())) { - versions.put(key, cachedVersion = moduleVersion); - break; - } + if (baseVersionsJson == null) { + return null; } - return cachedVersion; - } + Map baseVersions = new HashMap<>(); - /** - * checks if the module version cache contains the specified version - * and queries the meta server for this data if needed - * - * @return the json array with the maven data for all versions for - * this module version and mc version - */ - private JsonArray queryOslModuleVersions(String module, String version, GameSide side) throws Exception { - String mcVersion = mcVersion(); - Path moduleVersionCache = oslModuleVersionCache.get(mcVersion); + for (Map.Entry e : baseVersionsJson.entrySet()) { + JsonElement baseVersionJson = e.getValue(); - // the file can only be initialized after the Minecraft dependency - // has been declared so initially we set the value to null - if (moduleVersionCache == null) { - LoomGradleExtension loom = LoomGradleExtension.get(this.project); - Path userCache = loom.getFiles().getUserCache().toPath(); + if (!baseVersionJson.isJsonPrimitive()) { + continue; + } - moduleVersionCache = userCache.resolve(mcVersion).resolve("osl-module-versions.json"); - oslModuleVersionCache.put(mcVersion, moduleVersionCache); + String moduleName = e.getKey(); + String moduleVersion = baseVersionJson.getAsString(); + + baseVersions.put(moduleName, moduleVersion); } + return baseVersions; + } + + private void saveModuleBaseVersionsToCache(String version, Map baseVersions) throws Exception { + Path baseVersionsCache = moduleBaseVersionsCache(); JsonObject json = null; - // if the file does not exist, we create it - // and we cache the json object so we do not - // unnecessarily read the file for that again - if (!Files.exists(moduleVersionCache)) { + try (BufferedReader br = Files.newBufferedReader(baseVersionsCache)) { + json = GSON.fromJson(br, JsonObject.class); + } catch (NoSuchFileException e) { json = new JsonObject(); + } + + String generation = "gen" + intermediaryGeneration(); + JsonObject versionsJson = json.getAsJsonObject(generation); - // no need to write this to disk at this point - // the data is empty so the meta will be queried - // and once the data has been added the file will - // be written to disk + if (versionsJson == null) { + versionsJson = new JsonObject(); + json.add(generation, versionsJson); } - if (json == null) { - try (BufferedReader br = new BufferedReader(new FileReader(moduleVersionCache.toFile()))) { - json = GSON.fromJson(br, JsonObject.class); - } + + JsonObject baseVersionsJson = new JsonObject(); + versionsJson.add(version, baseVersionsJson); + + for (Map.Entry e : baseVersions.entrySet()) { + String moduleName = e.getKey(); + String moduleVersion = e.getValue(); + + baseVersionsJson.addProperty(moduleName, moduleVersion); } - JsonObject moduleJson = json.getAsJsonObject(module); + Files.createDirectories(baseVersionsCache.getParent()); + + try (BufferedWriter bw = Files.newBufferedWriter(baseVersionsCache)) { + GSON.toJson(json, bw); + } + } - if (moduleJson == null) { - moduleJson = new JsonObject(); - json.add(module, moduleJson); + public String getOslModuleVersion(String module, String version, GameSide side) { + String moduleVersion = moduleVersions.get(module + version + side.suffix()); - // no need to write this to disk at this point - // the data is empty so the meta will be queried - // and once the data has been added the file will - // be written to disk + if (moduleVersion == null) { + moduleVersions.put(module + version + side.suffix(), moduleVersion = getModuleVersion(module, version, side)); } - JsonArray versionsJson = moduleJson.getAsJsonArray(version); + return moduleVersion; + } - if (versionsJson == null) { - String metaUrl = String.format(Constants.META_URL + Constants.OSL_MODULE_META_ENDPOINT, - module, - mcVersion, - version); - - try (InputStreamReader ir = new InputStreamReader(new URL(metaUrl).openStream())) { - versionsJson = GSON.fromJson(ir, JsonArray.class); - moduleJson.add(version, versionsJson); + private String getModuleVersion(String module, String version, GameSide side) { + String moduleVersion = null; + + try { + moduleVersion = getModuleVersionFromMeta(module, version, side); + } catch (Exception me) { + try { + moduleVersion = getModuleVersionFromCache(module, version, side); + } catch (Exception ce) { + project.getLogger().warn("unable to read OSL module version from cache for gen" + intermediaryGeneration() + " " + module + " " + version, ce); } - Files.createDirectories(moduleVersionCache.getParent()); - try (BufferedWriter bw = new BufferedWriter(new FileWriter(moduleVersionCache.toFile()))) { - GSON.toJson(json, bw); + + if (moduleVersion == null) { + throw new IllegalStateException("unable to fetch OSL module version from meta for gen" + intermediaryGeneration() + " " + module + " " + version + ", and it is not in the cache", me); } } - return versionsJson; + return moduleVersion; + } + + private String getModuleVersionFromMeta(String module, String version, GameSide side) throws Exception { + String metaUrl = Constants.oslModuleVersionMetaEndpoint(intermediaryGeneration(), module, minecraftVersion(), version + side.suffix()); + + try (InputStreamReader ir = new InputStreamReader(new URI(metaUrl).toURL().openStream())) { + JsonArray modulesJson = GSON.fromJson(ir, JsonArray.class); + String moduleVersion = null; + + for (JsonElement e : modulesJson) { + if (!e.isJsonObject()) { + continue; + } + + JsonObject moduleJson = e.getAsJsonObject(); + moduleVersion = moduleJson.get("version").getAsString(); + + if (moduleVersion.contains(side.id()) || (!moduleVersion.contains(GameSide.CLIENT.id()) && !moduleVersion.contains(GameSide.SERVER.id()))) { + break; + } else { + moduleVersion = null; + } + } + + try { + saveModuleVersionToCache(module, version, side, moduleVersion); + } catch (Exception e) { + project.getLogger().warn("unable to save OSL module versions for gen" + intermediaryGeneration() + " " + module + " " + version + " to cache", e); + } + + return moduleVersion; + } + } + + private String getModuleVersionFromCache(String module, String version, GameSide side) throws Exception { + Path versionsCache = moduleVersionsCache(); + JsonObject json; + + try (BufferedReader br = Files.newBufferedReader(versionsCache)) { + json = GSON.fromJson(br, JsonObject.class); + } catch (NoSuchFileException e) { + return null; + } + + String generation = "gen" + intermediaryGeneration(); + JsonObject versionsJson = json.getAsJsonObject(generation); + + if (versionsJson == null) { + return null; + } + + JsonObject modulesJson = versionsJson.getAsJsonObject(version); + + if (modulesJson == null) { + return null; + } + + JsonObject moduleVersionsJson = modulesJson.getAsJsonObject(module); + + if (moduleVersionsJson == null) { + return null; + } + + return moduleVersionsJson.get(side.id()).getAsString(); + } + + private void saveModuleVersionToCache(String module, String version, GameSide side, String moduleVersion) throws Exception { + Path versionsCache = moduleVersionsCache(); + JsonObject json = null; + + try (BufferedReader br = Files.newBufferedReader(versionsCache)) { + json = GSON.fromJson(br, JsonObject.class); + } catch (NoSuchFileException e) { + json = new JsonObject(); + } + + String generation = "gen" + intermediaryGeneration(); + JsonObject versionsJson = json.getAsJsonObject(generation); + + if (versionsJson == null) { + versionsJson = new JsonObject(); + json.add(generation, versionsJson); + } + + JsonObject modulesJson = versionsJson.getAsJsonObject(version); + + if (modulesJson == null) { + modulesJson = new JsonObject(); + versionsJson.add(version, modulesJson); + } + + JsonObject moduleVersionsJson = modulesJson.getAsJsonObject(module); + + if (moduleVersionsJson == null) { + moduleVersionsJson = new JsonObject(); + modulesJson.add(module, moduleVersionsJson); + } + + moduleVersionsJson.add(side.id(), moduleVersionsJson); + + Files.createDirectories(versionsCache.getParent()); + + try (BufferedWriter bw = Files.newBufferedWriter(versionsCache)) { + GSON.toJson(json, bw); + } } } diff --git a/src/main/java/net/ornithemc/ploceus/PloceusGradleExtension.java b/src/main/java/net/ornithemc/ploceus/PloceusGradleExtension.java index dd0069d..cac8296 100644 --- a/src/main/java/net/ornithemc/ploceus/PloceusGradleExtension.java +++ b/src/main/java/net/ornithemc/ploceus/PloceusGradleExtension.java @@ -325,10 +325,10 @@ public void dependOsl(String version, GameSide side) throws Exception { @Override public void dependOsl(String configuration, String version, GameSide side) throws Exception { - for (Map.Entry entry : oslVersions.getDependencies(version).entrySet()) { + for (Map.Entry entry : oslVersions.getOslModuleBaseVersions(version).entrySet()) { String module = entry.getKey(); String baseVersion = entry.getValue(); - String moduleVersion = oslVersions.getVersion(module, baseVersion, side); + String moduleVersion = oslVersions.getOslModuleVersion(module, baseVersion, side); // not all modules cover all Minecraft versions // so check if a valid module version exists for @@ -356,7 +356,7 @@ public void dependOslModule(String version, GameSide side, String module) throws @Override public void dependOslModule(String configuration, String version, GameSide side, String module) throws Exception { - String baseVersion = oslVersions.getDependency(version, module); + String baseVersion = oslVersions.getOslModuleBaseVersion(version, module); if (baseVersion == null) { throw new RuntimeException("osl " + version + " " + module + " for " + side.id() + " does not exist"); @@ -377,7 +377,7 @@ public String oslModule(String module, String version, String side) throws Excep @Override public String oslModule(String module, String version, GameSide side) throws Exception { - String moduleVersion = oslVersions.getVersion(module, version, side); + String moduleVersion = oslVersions.getOslModuleVersion(module, version, side); if (moduleVersion == null) { throw new RuntimeException("osl " + module + " version " + version + " for " + side.id() + " does not exist"); @@ -388,7 +388,7 @@ public String oslModule(String module, String version, GameSide side) throws Exc private void addOslModuleDependency(String configuration, String module, String version) { project.getDependencies().add(configuration, String.format("%s:%s:%s", - Constants.OSL_MAVEN_GROUP, + Constants.oslMavenGroup(intermediaryGeneration.get()), module, version)); } From 377ebd21e772f624b6a31cbfc12c37e7b6b21f23 Mon Sep 17 00:00:00 2001 From: Space Walker Date: Sat, 15 Nov 2025 12:57:37 +0100 Subject: [PATCH 2/4] change osl version cache file names to avoid conflicts with previous ploceus versions --- .../java/net/ornithemc/ploceus/OslVersionCache.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java index 8a2677f..e1b0ae8 100644 --- a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java +++ b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java @@ -64,8 +64,9 @@ private Path moduleBaseVersionsCache() { if (moduleBaseVersionsCache == null) { LoomGradleExtension loom = LoomGradleExtension.get(project); Path userCache = loom.getFiles().getUserCache().toPath(); - - moduleBaseVersionsCache = userCache.resolve("osl-versions.json"); + + // avoid conflicts with previous Ploceus versions, which used 'osl-versions.json' + moduleBaseVersionsCache = userCache.resolve("osl-base-versions.json"); } return moduleBaseVersionsCache; @@ -75,8 +76,9 @@ private Path moduleVersionsCache() { if (moduleVersionsCache == null) { LoomGradleExtension loom = LoomGradleExtension.get(project); Path userCache = loom.getFiles().getUserCache().toPath(); - - moduleVersionsCache = userCache.resolve(minecraftVersion()).resolve("osl-module-versions.json"); + + // avoid conflicts with previous Ploceus versions, which used 'osl-module-versions.json' + moduleVersionsCache = userCache.resolve(minecraftVersion()).resolve("osl-versions.json"); } return moduleVersionsCache; From 8dc09a0a5e101bd650b2e3a8f1fbf972a348855c Mon Sep 17 00:00:00 2001 From: Space Walker Date: Sat, 15 Nov 2025 13:08:12 +0100 Subject: [PATCH 3/4] fix meta endpoint urls --- src/main/java/net/ornithemc/ploceus/OslVersionCache.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java index e1b0ae8..789ba04 100644 --- a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java +++ b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java @@ -119,7 +119,7 @@ private Map getModuleBaseVersions(String version) { } private Map getModuleBaseVersionsFromMeta(String version) throws Exception { - String metaUrl = Constants.oslVersionMetaEndpoint(intermediaryGeneration(), version); + String metaUrl = Constants.META_URL + Constants.oslVersionMetaEndpoint(intermediaryGeneration(), version); try (InputStreamReader ir = new InputStreamReader(new URI(metaUrl).toURL().openStream())) { JsonArray modulesJson = GSON.fromJson(ir, JsonArray.class); @@ -255,7 +255,7 @@ private String getModuleVersion(String module, String version, GameSide side) { } private String getModuleVersionFromMeta(String module, String version, GameSide side) throws Exception { - String metaUrl = Constants.oslModuleVersionMetaEndpoint(intermediaryGeneration(), module, minecraftVersion(), version + side.suffix()); + String metaUrl = Constants.META_URL + Constants.oslModuleVersionMetaEndpoint(intermediaryGeneration(), module, minecraftVersion(), version + side.suffix()); try (InputStreamReader ir = new InputStreamReader(new URI(metaUrl).toURL().openStream())) { JsonArray modulesJson = GSON.fromJson(ir, JsonArray.class); From fb7b10fea93a84c17e737a4f2b8d652a01e7096b Mon Sep 17 00:00:00 2001 From: Space Walker Date: Sat, 15 Nov 2025 13:18:31 +0100 Subject: [PATCH 4/4] fix recursive json --- .../ornithemc/ploceus/OslVersionCache.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java index 789ba04..36fb38f 100644 --- a/src/main/java/net/ornithemc/ploceus/OslVersionCache.java +++ b/src/main/java/net/ornithemc/ploceus/OslVersionCache.java @@ -303,19 +303,19 @@ private String getModuleVersionFromCache(String module, String version, GameSide return null; } - JsonObject modulesJson = versionsJson.getAsJsonObject(version); + JsonObject moduleJson = versionsJson.getAsJsonObject(module); - if (modulesJson == null) { + if (moduleJson == null) { return null; } - JsonObject moduleVersionsJson = modulesJson.getAsJsonObject(module); + JsonObject moduleVersionJson = moduleJson.getAsJsonObject(version); - if (moduleVersionsJson == null) { + if (moduleVersionJson == null) { return null; } - return moduleVersionsJson.get(side.id()).getAsString(); + return moduleVersionJson.get(side.id()).getAsString(); } private void saveModuleVersionToCache(String module, String version, GameSide side, String moduleVersion) throws Exception { @@ -329,28 +329,28 @@ private void saveModuleVersionToCache(String module, String version, GameSide si } String generation = "gen" + intermediaryGeneration(); - JsonObject versionsJson = json.getAsJsonObject(generation); + JsonObject modulesJson = json.getAsJsonObject(generation); - if (versionsJson == null) { - versionsJson = new JsonObject(); - json.add(generation, versionsJson); + if (modulesJson == null) { + modulesJson = new JsonObject(); + json.add(generation, modulesJson); } - JsonObject modulesJson = versionsJson.getAsJsonObject(version); + JsonObject moduleJson = modulesJson.getAsJsonObject(module); - if (modulesJson == null) { - modulesJson = new JsonObject(); - versionsJson.add(version, modulesJson); + if (moduleJson == null) { + moduleJson = new JsonObject(); + modulesJson.add(module, moduleJson); } - JsonObject moduleVersionsJson = modulesJson.getAsJsonObject(module); + JsonObject moduleVersionJson = moduleJson.getAsJsonObject(version); - if (moduleVersionsJson == null) { - moduleVersionsJson = new JsonObject(); - modulesJson.add(module, moduleVersionsJson); + if (moduleVersionJson == null) { + moduleVersionJson = new JsonObject(); + moduleJson.add(version, moduleVersionJson); } - moduleVersionsJson.add(side.id(), moduleVersionsJson); + moduleVersionJson.addProperty(side.id(), moduleVersion); Files.createDirectories(versionsCache.getParent());