From a4632e4cf1b0471a1c6073fc87f442b224b390c4 Mon Sep 17 00:00:00 2001 From: The Judge Date: Sun, 22 Sep 2024 19:33:45 -0700 Subject: [PATCH] Update instances.json on mods update --- .../pojlib/util/json/MinecraftInstances.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/java/pojlib/util/json/MinecraftInstances.java b/src/main/java/pojlib/util/json/MinecraftInstances.java index f38902aa..8d43fd17 100644 --- a/src/main/java/pojlib/util/json/MinecraftInstances.java +++ b/src/main/java/pojlib/util/json/MinecraftInstances.java @@ -152,27 +152,31 @@ private void removeOldMods(ModsJson oldMods, ModsJson newMods) { } private void updateModByType(List newMods) throws IOException { - for(ProjectInfo extMod : extProjects) { - boolean manual = true; - for(ProjectInfo newMod : newMods) { - if(!extMod.slug.equals(newMod.slug)) { - continue; - } - manual = false; - File mod = new File(gameDir + (newMod.type.equals("mod") ? "/mods" : "/resourcepacks"), newMod.slug + ".jar"); - if(!mod.exists() || !extMod.version.equals(newMod.version)) { - DownloadUtils.downloadFile(newMod.download_link, mod); - break; - } - } - if(manual) { - File mod = new File(gameDir + (extMod.type.equals("mod") ? "/mods" : "/resourcepacks"), extMod.slug + ".jar"); - if(!mod.exists()) { - DownloadUtils.downloadFile(extMod.download_link, mod); - break; - } - } - } + ArrayList newExtMods = new ArrayList<>(); + for(ProjectInfo extMod : extProjects) { + boolean manual = true; + for(ProjectInfo newMod : newMods) { + if(!extMod.slug.equals(newMod.slug)) { + continue; + } + manual = false; + File mod = new File(gameDir + (newMod.type.equals("mod") ? "/mods" : "/resourcepacks"), newMod.slug + ".jar"); + if(!mod.exists() || !extMod.version.equals(newMod.version)) { + DownloadUtils.downloadFile(newMod.download_link, mod); + extMod = newMod; + break; + } + } + if(manual) { + File mod = new File(gameDir + (extMod.type.equals("mod") ? "/mods" : "/resourcepacks"), extMod.slug + ".jar"); + if(!mod.exists()) { + DownloadUtils.downloadFile(extMod.download_link, mod); + } + } + newExtMods.add(extMod); + } + + extProjects = newExtMods.toArray(new ProjectInfo[0]); } private void downloadAllMods(List newMods) throws IOException {