@@ -479,6 +479,10 @@ private static void update(String[] args) {
479479 for (String id : Arrays .stream (args ).skip (1 ).toArray (String []::new )) {
480480 try {
481481 if (!Utils .isInteger (id )) throw new NoSuchObjectException ("Mod ID is invalid: " + id );
482+ if (!mods .containsKey (Integer .parseInt (id ))) {
483+ System .out .println (Ansi .ansi ().fg (Ansi .Color .YELLOW ).a ("Cannot find mod with ID " + id + " installed. Skipping updating this mod..." ));
484+ continue ;
485+ }
482486 JSONObject json = Utils .runRetry (() -> (JSONObject ) Utils .readJsonFromUrl (Constants .CURSEFORGE_API + id ));
483487 if (((long ) ((JSONObject ) json .get ("categorySection" )).get ("gameCategoryId" )) != 6 )
484488 throw new NoSuchObjectException ("The ID " + id + " does not represent a mod." );
@@ -490,11 +494,11 @@ private static void update(String[] args) {
490494 JSONObject bestFile = (JSONObject ) f .get (0 );
491495 Map .Entry <Integer , String > entry = mods .get (Integer .parseInt (id ));
492496 if (((long ) bestFile .get ("id" )) > entry .getKey ()) {
493- System .out .println (Ansi .ansi ().fg (Ansi .Color .YELLOW ).a (entry .getValue ()).reset ().a (" | " ).fg (Ansi .Color .MAGENTA ).a (entry . getKey () ));
497+ System .out .println (Ansi .ansi ().fg (Ansi .Color .YELLOW ).a (entry .getValue ()).reset ().a (" | " ).fg (Ansi .Color .MAGENTA ).a (id ));
494498 String downloadUrl = ((String ) bestFile .get ("downloadUrl" )).replaceFirst ("edge" , "media" );
495- if (mods .containsKey (Integer .parseInt (id )))
496- new File (profileConfig .getParent () + File .separator + "mods" + File .separator + entry .getValue () + "_" + id + "_" + entry .getKey () + ".jar" ).delete ();
497499 String loc = Utils .downloadFile (downloadUrl , profileConfig .getParent () + File .separator + "mods" , ((String ) bestFile .get ("fileName" )).replace (".jar" , "_" + id + "_" + bestFile .get ("id" ) + ".jar" ));
500+ if (loc == null ) continue ;
501+ new File (profileConfig .getParent () + File .separator + "mods" + File .separator + entry .getValue () + "_" + id + "_" + entry .getKey () + ".jar" ).delete ();
498502 System .out .println (Ansi .ansi ().fg (Ansi .Color .GREEN ).a ("Downloaded " + loc ));
499503 }
500504 } catch (Exception e ) {
0 commit comments