diff --git a/.gradle/7.4/checksums/checksums.lock b/.gradle/7.4/checksums/checksums.lock index 3357585..b22bc02 100644 Binary files a/.gradle/7.4/checksums/checksums.lock and b/.gradle/7.4/checksums/checksums.lock differ diff --git a/.gradle/7.4/checksums/sha1-checksums.bin b/.gradle/7.4/checksums/sha1-checksums.bin index 95084f2..85e718a 100644 Binary files a/.gradle/7.4/checksums/sha1-checksums.bin and b/.gradle/7.4/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.bin b/.gradle/7.4/executionHistory/executionHistory.bin index 791bd5f..4ac08c3 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.bin and b/.gradle/7.4/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.lock b/.gradle/7.4/executionHistory/executionHistory.lock index 473f98c..8d2ab50 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.lock and b/.gradle/7.4/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.4/fileHashes/fileHashes.bin b/.gradle/7.4/fileHashes/fileHashes.bin index fa2e27e..d81f909 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.bin and b/.gradle/7.4/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.4/fileHashes/fileHashes.lock b/.gradle/7.4/fileHashes/fileHashes.lock index b283bae..de296c3 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.lock and b/.gradle/7.4/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.4/fileHashes/resourceHashesCache.bin b/.gradle/7.4/fileHashes/resourceHashesCache.bin index a6f3053..fda0f2a 100644 Binary files a/.gradle/7.4/fileHashes/resourceHashesCache.bin and b/.gradle/7.4/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 416e1bf..ba7b507 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e36883f..3ead959 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/classes/java/main/com/calebfontenot/Common.class b/build/classes/java/main/com/calebfontenot/Common.class index 9512095..3aace11 100644 Binary files a/build/classes/java/main/com/calebfontenot/Common.class and b/build/classes/java/main/com/calebfontenot/Common.class differ diff --git a/build/classes/java/main/com/calebfontenot/Main.class b/build/classes/java/main/com/calebfontenot/Main.class index aa347c6..255939c 100644 Binary files a/build/classes/java/main/com/calebfontenot/Main.class and b/build/classes/java/main/com/calebfontenot/Main.class differ diff --git a/build/classes/java/main/com/calebfontenot/parsers/Velocity.class b/build/classes/java/main/com/calebfontenot/parsers/Velocity.class index e7aec23..8eb6cbd 100644 Binary files a/build/classes/java/main/com/calebfontenot/parsers/Velocity.class and b/build/classes/java/main/com/calebfontenot/parsers/Velocity.class differ diff --git a/build/libs/Minecraft-Updater-Java-1.0-SNAPSHOT-all.jar b/build/libs/Minecraft-Updater-Java-1.0-SNAPSHOT-all.jar index 925ea99..57b7315 100644 Binary files a/build/libs/Minecraft-Updater-Java-1.0-SNAPSHOT-all.jar and b/build/libs/Minecraft-Updater-Java-1.0-SNAPSHOT-all.jar differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 0c3ee0f..d36fc46 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/calebfontenot/Common.java b/src/main/java/com/calebfontenot/Common.java index 57dcde8..fda64ec 100644 --- a/src/main/java/com/calebfontenot/Common.java +++ b/src/main/java/com/calebfontenot/Common.java @@ -9,11 +9,8 @@ import java.util.ArrayList; import java.util.List; public class Common { - public static List parse(String fetchURL, String keyToFetch) throws Exception { - //System.out.println("CURLing API..."); - URL url = new URL(fetchURL); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"))) { - for (String line; (line = reader.readLine()) != null; ) { + public static List parseKey(String fetchURL, String keyToFetch) throws Exception { + String line = rawFetch(fetchURL); JSONObject json = new JSONObject(line); //System.out.println(line); JSONArray key = json.getJSONArray(keyToFetch); @@ -25,12 +22,6 @@ public class Common { return returnList; } - } catch (Exception IllegalArgumentException) { - return null; - } - return null; - } - public static String rawFetch(String fetchURL) throws Exception { //System.out.println("CURLing API..."); URL url = new URL(fetchURL); @@ -48,4 +39,15 @@ public class Common { } return null; } + public static String regex(String fetchURL) throws Exception{ // Regexes off the start and end square braces returned by certain APIs? + String raw = rawFetch(fetchURL); + raw = raw.substring(1, raw.length() - 1); + return raw; + } + public static String parse(String fetchURL, String keyToFetch) throws Exception{ + String raw = regex(fetchURL); + JSONTokener tokener = new JSONTokener(raw); + JSONObject object = new JSONObject(tokener); + return object.getString(keyToFetch); + } } diff --git a/src/main/java/com/calebfontenot/Main.java b/src/main/java/com/calebfontenot/Main.java index e805ab8..e4cce2f 100644 --- a/src/main/java/com/calebfontenot/Main.java +++ b/src/main/java/com/calebfontenot/Main.java @@ -52,7 +52,7 @@ public class Main { userInput = input.nextInt(); if (userInput == 1) { // user has selected PaperMC System.out.println("Available Projects: "); - List projects = Common.parse(PAPER_API_URL + "/projects", "projects"); + List projects = Common.parseKey(PAPER_API_URL + "/projects", "projects"); int i = 1; for (String projectNames : projects) { System.out.println(i + ". " + projectNames); diff --git a/src/main/java/com/calebfontenot/parsers/Velocity.java b/src/main/java/com/calebfontenot/parsers/Velocity.java index 6ca7264..25da639 100644 --- a/src/main/java/com/calebfontenot/parsers/Velocity.java +++ b/src/main/java/com/calebfontenot/parsers/Velocity.java @@ -5,6 +5,6 @@ import com.calebfontenot.Common; public class Velocity { public static final String MODRINTH_API_URL = "https://api.modrinth.com/v2"; public static void fetchVersions(String modID) throws Exception { // Fetch information about mod versions from the API. - System.out.println(Common.rawFetch(MODRINTH_API_URL + "/project/" + modID + "/version")); + System.out.println(Common.parse(MODRINTH_API_URL + "/project/" + modID + "/version", "id")); } }