mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
[CI-SKIP] Update version checker to use V2 downloads API (#5728)
This commit is contained in:
parent
2667fd04c4
commit
152c94320f
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user