[CI-SKIP] Update version checker to use V2 downloads API (#5728)

This commit is contained in:
Prof-Bloodstone 2021-05-27 15:25:24 +02:00 committed by GitHub
parent b9f2a673d3
commit cd4defec04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -6,10 +6,10 @@ Subject: [PATCH] Implement Paper VersionChecker
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..c8b911e5d013525ffc5d2911ee0e421dd916cb00
index 0000000000000000000000000000000000000000..1a1b50e475b9ede544b2f6d0d36632b24b68898c
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
@@ -0,0 +1,117 @@
@@ -0,0 +1,122 @@
+package com.destroystokyo.paper;
+
+import com.destroystokyo.paper.util.VersionFetcher;
@ -24,6 +24,7 @@ index 0000000000000000000000000000000000000000..c8b911e5d013525ffc5d2911ee0e421d
+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..c8b911e5d013525ffc5d2911ee0e421d
+ 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();

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Add version history to version command
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
index c8b911e5d013525ffc5d2911ee0e421dd916cb00..dc0ea65ab87255fad0d54dfb509300098a0b4864 100644
index 1a1b50e475b9ede544b2f6d0d36632b24b68898c..580bae0d414d371a07a6bfeefc41fdd989dc0083 100644
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
@@ -5,7 +5,9 @@ import com.google.common.base.Charsets;
@ -18,7 +18,7 @@ index c8b911e5d013525ffc5d2911ee0e421dd916cb00..dc0ea65ab87255fad0d54dfb50930009
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -27,7 +29,10 @@ public class PaperVersionFetcher implements VersionFetcher {
@@ -28,7 +30,10 @@ public class PaperVersionFetcher implements VersionFetcher {
@Override
public Component getVersionMessage(@Nonnull String serverVersion) {
String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]");
@ -30,7 +30,7 @@ index c8b911e5d013525ffc5d2911ee0e421dd916cb00..dc0ea65ab87255fad0d54dfb50930009
}
private static @Nullable String getMinecraftVersion() {
@@ -114,4 +119,19 @@ public class PaperVersionFetcher implements VersionFetcher {
@@ -119,4 +124,19 @@ public class PaperVersionFetcher implements VersionFetcher {
return -1;
}
}