From 152c94320f720114fd84fbe52f59bf23a4d3c96e Mon Sep 17 00:00:00 2001 From: Prof-Bloodstone <46570876+Prof-Bloodstone@users.noreply.github.com> Date: Thu, 27 May 2021 15:25:24 +0200 Subject: [PATCH] [CI-SKIP] Update version checker to use V2 downloads API (#5728) --- .../Implement-Paper-VersionChecker.patch | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch b/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch index a88268bc29..37d1f0441a 100644 --- a/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch +++ b/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch @@ -24,6 +24,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; ++import java.util.stream.StreamSupport; + +public class PaperVersionFetcher implements VersionFetcher { + private static final java.util.regex.Pattern VER_PATTERN = java.util.regex.Pattern.compile("^([0-9\\.]*)\\-.*R"); // R is an anchor, will always give '-R' at end @@ -84,11 +85,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (siteApiVersion == null) { return -1; } + try { + try (BufferedReader reader = Resources.asCharSource( -+ new URL("https://papermc.io/api/v1/paper/" + siteApiVersion + "/latest"), ++ new URL("https://papermc.io/api/v2/projects/paper/versions/" + siteApiVersion), + Charsets.UTF_8 + ).openBufferedStream()) { + JsonObject json = new Gson().fromJson(reader, JsonObject.class); -+ int latest = json.get("build").getAsInt(); ++ JsonArray builds = json.getAsJsonArray("builds"); ++ int latest = StreamSupport.stream(builds.spliterator(), false) ++ .mapToInt(e -> e.getAsInt()) ++ .max() ++ .getAsInt(); + return latest - jenkinsBuild; + } catch (JsonSyntaxException ex) { + ex.printStackTrace();