3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 11:00:06 +01:00

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

Dieser Commit ist enthalten in:
Prof-Bloodstone 2021-05-27 15:25:24 +02:00 committet von GitHub
Ursprung b9f2a673d3
Commit cd4defec04
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 12 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -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();

Datei anzeigen

@ -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;
}
}