From f3972e3d8e392d9f774fa668a67bbfb4631441cc Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Sat, 9 Dec 2023 17:25:53 +0100 Subject: [PATCH] Refactor: assume modrinth may not give a SHA 1 --- .../modloaders/modpacks/api/ModrinthApi.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ModrinthApi.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ModrinthApi.java index e79b5ad0fd..be345d28f1 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ModrinthApi.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ModrinthApi.java @@ -86,8 +86,15 @@ public ModDetail getModDetails(ModItem item) { names[i] = version.get("name").getAsString(); mcNames[i] = version.get("game_versions").getAsJsonArray().get(0).getAsString(); urls[i] = version.get("files").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString(); - hashes[i] = version.getAsJsonArray("files").get(0).getAsJsonObject() - .get("hashes").getAsJsonObject().get("sha1").getAsString(); + // Assume there may not be hashes, in case the API changes + JsonObject hashesMap = version.getAsJsonArray("files").get(0).getAsJsonObject() + .get("hashes").getAsJsonObject(); + if(hashesMap == null || hashesMap.get("sha1") == null){ + hashes[i] = null; + continue; + } + + hashes[i] = hashesMap.get("sha1").getAsString(); } return new ModDetail(item, names, mcNames, urls, hashes);