From 9625d3ef567b16e0f0648b3c374809439a89cace Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 12:45:21 -0400 Subject: [PATCH 1/6] fix force update error --- .../client/tasks/updater/plugins/TaskPluginsUpdater.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/TaskPluginsUpdater.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/TaskPluginsUpdater.java index 62e83437..dfbaa578 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/TaskPluginsUpdater.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/TaskPluginsUpdater.java @@ -488,7 +488,8 @@ private void doDownloadLogic(@NotNull MinecraftPlugin pl, SearchResult result) { String resultBukkitId = result.getBukkitId(); if (pl.getCustomDownloadURL() != null) downloadUrl = pl.getCustomDownloadURL(); - if (pl.forceUpdate.equals("true") && code == 0) + if (pl.forceUpdate != null && code == 0) + if (pl.forceUpdate.equals("true")) code = 1; if (code == 0) { From 3362639905674d3f1292c9ccfa208db986dcf6d2 Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:46:00 -0400 Subject: [PATCH 2/6] fix update check not working with json object response --- .../client/tasks/updater/search/CustomCheckURL.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java index 25d8a8c0..440b7322 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java @@ -41,7 +41,11 @@ public SearchResult doCustomCheck(MinecraftPlugin plugin) { release = Json.getAsJsonArray(url) .get(0).getAsJsonObject(); } catch (Exception e) { - throw e; + try { + release = Json.getAsJsonObject(url); + } catch (Exeption ex){ + throw ex; + } } String[] versionNaming = {"version_number", "version"}; From 0b463f2961ed44a8158afe2ba6440b585e0f4271 Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:51:13 -0400 Subject: [PATCH 3/6] Update CustomCheckURL.java --- .../autoplug/client/tasks/updater/search/CustomCheckURL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java index 1ced3c45..bd9168c1 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java @@ -41,7 +41,7 @@ public SearchResult doCustomCheck(String url, String currentVersion) { } catch (Exception e) { try { release = Json.getAsJsonObject(url); - } catch (Exeption ex){ + } catch (Exception ex){ throw ex; } } From 43e844acf3901c6582484ee6ffc7509516900478 Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:17:12 -0400 Subject: [PATCH 4/6] Update CustomCheckURL.java --- .../tasks/updater/search/CustomCheckURL.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java index bd9168c1..8319f3ea 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java @@ -34,16 +34,15 @@ public SearchResult doCustomCheck(String url, String currentVersion) { String downloadUrl = null; SearchResult.Type code = SearchResult.Type.UP_TO_DATE; try { + JsonElement response = Json.get(url); JsonObject release; - try { - release = Json.getAsJsonArray(url) - .get(0).getAsJsonObject(); - } catch (Exception e) { - try { - release = Json.getAsJsonObject(url); - } catch (Exception ex){ - throw ex; - } + + if (response.isJsonArray()) { + release = response.getAsJsonArray().get(0).getAsJsonObject(); + } else if (response.isJsonObject()) { + release = response.getAsJsonObject(); + } else { + throw new IllegalArgumentException("Invalid JSON response format"); } String[] versionNaming = {"version_number", "version"}; From d09373cf8c4ece379fc90a40cd24f1eb086427fd Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:19:37 -0400 Subject: [PATCH 5/6] Update CustomCheckURL.java --- .../client/tasks/updater/search/CustomCheckURL.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java index 8319f3ea..9ed6cb8f 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java @@ -38,9 +38,17 @@ public SearchResult doCustomCheck(String url, String currentVersion) { JsonObject release; if (response.isJsonArray()) { - release = response.getAsJsonArray().get(0).getAsJsonObject(); + try { + release = response.getAsJsonArray().get(0).getAsJsonObject(); + } catch (Exception e) { + throw e; + } } else if (response.isJsonObject()) { - release = response.getAsJsonObject(); + try { + release = response.getAsJsonObject(); + } catch (Exception e) { + throw e; + } } else { throw new IllegalArgumentException("Invalid JSON response format"); } From eb2df5df7840f44fcd20c25ab426a023081a80e2 Mon Sep 17 00:00:00 2001 From: vengestone-dragoon <97992930+vengestone-dragoon@users.noreply.github.com> Date: Sun, 23 Jun 2024 17:25:31 -0400 Subject: [PATCH 6/6] major rewrite, check succeded --- .../tasks/updater/search/CustomCheckURL.java | 102 +++++++++++++----- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java index 9ed6cb8f..79ddb595 100644 --- a/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java +++ b/src/main/java/com/osiris/autoplug/client/tasks/updater/search/CustomCheckURL.java @@ -8,9 +8,10 @@ package com.osiris.autoplug.client.tasks.updater.search; -import com.google.gson.JsonObject; +import com.google.gson.*; import com.osiris.autoplug.client.utils.UtilsURL; import com.osiris.jlib.json.Json; +import java.util.ArrayList; public class CustomCheckURL { @@ -39,13 +40,15 @@ public SearchResult doCustomCheck(String url, String currentVersion) { if (response.isJsonArray()) { try { - release = response.getAsJsonArray().get(0).getAsJsonObject(); + latest = traverseJsonArray(response.getAsJsonArray(), (byte) 0); + downloadUrl = traverseJsonArray(response.getAsJsonArray(), (byte) 1); } catch (Exception e) { throw e; } } else if (response.isJsonObject()) { try { - release = response.getAsJsonObject(); + latest = traverseJsonObject(response.getAsJsonObject(), (byte) 0); + downloadUrl = traverseJsonObject(response.getAsJsonObject(), (byte) 1); } catch (Exception e) { throw e; } @@ -53,30 +56,6 @@ public SearchResult doCustomCheck(String url, String currentVersion) { throw new IllegalArgumentException("Invalid JSON response format"); } - String[] versionNaming = {"version_number", "version"}; - - for (String naming : versionNaming) { - if (release.has(naming)) { - String version = release.get(naming).getAsString().replaceAll("[^0-9.]", ""); - if (!version.isEmpty()) { - latest = version; - break; - } - } - } - - String[] downloadNaming = {"download_url", "download", "file", "download_file"}; - - for (String naming : downloadNaming) { - if (release.has(naming)) { - String durl = release.get(naming).getAsString(); - if (!durl.isEmpty()) { - downloadUrl = durl; - break; - } - } - } - String[] pluginVersionComponents = currentVersion.split("\\."); String[] latestVersionComponents = latest.split("\\."); @@ -105,4 +84,73 @@ public SearchResult doCustomCheck(String url, String currentVersion) { result.setException(exception); return result; } + + private String getLatestVersionFromRe(JsonObject release){ + + String[] versionNaming = {"version_number", "version"}; + String latest = null; + + for (String naming : versionNaming) { + if (release.has(naming)) { + String version = release.get(naming).getAsString().replaceAll("[^0-9.]", ""); + if (!version.isEmpty()) { + latest = version; + break; + } + } + } + return latest; + } + + private String getDownloadFromRe(JsonObject release){ + + String[] downloadNaming = {"download_url", "download", "file", "download_file"}; + String downloadUrl = null; + + for (String naming : downloadNaming) { + if (release.has(naming)) { + String durl = release.get(naming).getAsString(); + if (!durl.isEmpty()) { + downloadUrl = durl; + break; + } + } + } + return downloadUrl; + } + + private String traverseJsonArray(JsonArray jsonArray, byte lookingFor) { + String r = null; + for (JsonElement element : jsonArray) { + if (element.isJsonObject()) { + r = traverseJsonObject(element.getAsJsonObject(),lookingFor); + } else if (element.isJsonArray()) { + r = traverseJsonArray(element.getAsJsonArray(),lookingFor); + } + if (r != null) + break; + } + return r; + } + + private String traverseJsonObject(JsonObject jsonObject, byte lookingFor) { + String r = null; + for (String key : jsonObject.keySet()) { + JsonElement element = jsonObject.get(key); + if (element.isJsonObject()) { + r = traverseJsonObject(element.getAsJsonObject(),lookingFor); + } else if (element.isJsonArray()) { + r = traverseJsonArray(element.getAsJsonArray(),lookingFor); + } + if (r != null) + break; + } + + if (lookingFor == 0) { + r = getLatestVersionFromRe(jsonObject.getAsJsonObject()); + } else if (lookingFor == 1) { + r = getDownloadFromRe(jsonObject.getAsJsonObject()); + } + return r; + } }