mirror of
https://github.com/PaperMC/Paper.git
synced 2024-08-26 22:50:23 +02:00
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues. Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong. This is now resolved. Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me. Please as always, backup your worlds and test before updating to 1.16.2! If you update to 1.16.2, there is no going back to an older build than this. --------------------------------- Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com> Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com> Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com> Co-authored-by: stonar96 <minecraft.stonar96@gmail.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Jason <jasonpenilla2@me.com> Co-authored-by: kashike <kashike@vq.lc> Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: KennyTV <kennytv@t-online.de> Co-authored-by: commandblockguy <commandblockguy1@gmail.com> Co-authored-by: DigitalRegent <misterwener@gmail.com> Co-authored-by: ishland <ishlandmc@yeah.net>
144 lines
6.1 KiB
Diff
144 lines
6.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <zach@zachbr.io>
|
|
Date: Mon, 27 May 2019 03:40:05 -0500
|
|
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..5deed3e25ff41ab0a4015a5fd0c1e952cdb16402
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
|
@@ -0,0 +1,115 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+import com.destroystokyo.paper.util.VersionFetcher;
|
|
+import com.google.common.base.Charsets;
|
|
+import com.google.common.io.Resources;
|
|
+import com.google.gson.*;
|
|
+
|
|
+import javax.annotation.Nonnull;
|
|
+import javax.annotation.Nullable;
|
|
+import java.io.*;
|
|
+import java.net.HttpURLConnection;
|
|
+import java.net.URL;
|
|
+
|
|
+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
|
|
+ private static final String GITHUB_BRANCH_NAME = "master";
|
|
+ private static @Nullable String mcVer;
|
|
+
|
|
+ @Override
|
|
+ public long getCacheTime() {
|
|
+ return 720000;
|
|
+ }
|
|
+
|
|
+ @Nonnull
|
|
+ @Override
|
|
+ public String getVersionMessage(@Nonnull String serverVersion) {
|
|
+ String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]");
|
|
+ return getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]);
|
|
+ }
|
|
+
|
|
+ private static @Nullable String getMinecraftVersion() {
|
|
+ if (mcVer == null) {
|
|
+ java.util.regex.Matcher matcher = VER_PATTERN.matcher(org.bukkit.Bukkit.getBukkitVersion());
|
|
+ if (matcher.find()) {
|
|
+ String result = matcher.group();
|
|
+ mcVer = result.substring(0, result.length() - 2); // strip 'R' anchor and trailing '-'
|
|
+ } else {
|
|
+ org.bukkit.Bukkit.getLogger().warning("Unable to match version to pattern! Report to PaperMC!");
|
|
+ org.bukkit.Bukkit.getLogger().warning("Pattern: " + VER_PATTERN.toString());
|
|
+ org.bukkit.Bukkit.getLogger().warning("Version: " + org.bukkit.Bukkit.getBukkitVersion());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return mcVer;
|
|
+ }
|
|
+
|
|
+ private static String getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) {
|
|
+ int distance;
|
|
+ try {
|
|
+ int jenkinsBuild = Integer.parseInt(versionInfo);
|
|
+ distance = fetchDistanceFromSiteApi(jenkinsBuild, getMinecraftVersion());
|
|
+ } catch (NumberFormatException ignored) {
|
|
+ versionInfo = versionInfo.replace("\"", "");
|
|
+ distance = fetchDistanceFromGitHub(repo, branch, versionInfo);
|
|
+ }
|
|
+
|
|
+ switch (distance) {
|
|
+ case -1:
|
|
+ return "Error obtaining version information";
|
|
+ case 0:
|
|
+ return "You are running the latest version";
|
|
+ case -2:
|
|
+ return "Unknown version";
|
|
+ default:
|
|
+ return "You are " + distance + " version(s) behind";
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static int fetchDistanceFromSiteApi(int jenkinsBuild, @Nullable String siteApiVersion) {
|
|
+ if (siteApiVersion == null) { return -1; }
|
|
+ try {
|
|
+ try (BufferedReader reader = Resources.asCharSource(
|
|
+ new URL("https://papermc.io/api/v1/paper/" + siteApiVersion + "/latest"),
|
|
+ Charsets.UTF_8
|
|
+ ).openBufferedStream()) {
|
|
+ JsonObject json = new Gson().fromJson(reader, JsonObject.class);
|
|
+ int latest = json.get("build").getAsInt();
|
|
+ return latest - jenkinsBuild;
|
|
+ } catch (JsonSyntaxException ex) {
|
|
+ ex.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
+ } catch (IOException e) {
|
|
+ e.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Contributed by Techcable <Techcable@outlook.com> in GH-65
|
|
+ private static int fetchDistanceFromGitHub(@Nonnull String repo, @Nonnull String branch, @Nonnull String hash) {
|
|
+ try {
|
|
+ HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
|
|
+ connection.connect();
|
|
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return -2; // Unknown commit
|
|
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))) {
|
|
+ JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
|
|
+ String status = obj.get("status").getAsString();
|
|
+ switch (status) {
|
|
+ case "identical":
|
|
+ return 0;
|
|
+ case "behind":
|
|
+ return obj.get("behind_by").getAsInt();
|
|
+ default:
|
|
+ return -1;
|
|
+ }
|
|
+ } catch (JsonSyntaxException | NumberFormatException e) {
|
|
+ e.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
+ } catch (IOException e) {
|
|
+ e.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 9828935e0ab1d7bc9950f3d9225542af3d0bf5b5..66925d9c3be206bb4fc4e88b247b099a2432b200 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -323,6 +323,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public String getTimingsServerName() {
|
|
return com.destroystokyo.paper.PaperConfig.timingsServerName;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
|
|
+ return new com.destroystokyo.paper.PaperVersionFetcher();
|
|
+ }
|
|
// Paper end
|
|
|
|
/**
|