mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 01:10:37 +01:00
1e39773b53
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 9d0221aa API to get client side view distance. 9be7f0ea SPIGOT-4395: Additions to PlayerBedEnterEvent. 01e534c6 Minor cosmetic cleanups to imports etc CraftBukkit Changes:96c461b3
API to get client side view distance.e2785f4e
Remove note about development builda8000588
SPIGOT-4395: Additions to PlayerBedEnterEvent. Spigot Changes: 117d4f7e Rebuild patches
152 lines
6.3 KiB
Diff
152 lines
6.3 KiB
Diff
From 121fabf8e1502b935c8d3f94635247b6d369de24 Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <zach.brown@destroystokyo.com>
|
|
Date: Mon, 29 Feb 2016 17:58:01 -0600
|
|
Subject: [PATCH] Check Paper versions
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
index 5a994953b..f38f68640 100644
|
|
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
@@ -26,6 +26,11 @@ import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.JSONParser;
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
+// Paper start
|
|
+import java.io.InputStreamReader;
|
|
+import java.net.HttpURLConnection;
|
|
+// Paper end
|
|
+
|
|
public class VersionCommand extends BukkitCommand {
|
|
public VersionCommand(String name) {
|
|
super(name);
|
|
@@ -149,7 +154,7 @@ public class VersionCommand extends BukkitCommand {
|
|
|
|
private void sendVersion(CommandSender sender) {
|
|
if (hasVersion) {
|
|
- if (System.currentTimeMillis() - lastCheck > 21600000) {
|
|
+ if (System.currentTimeMillis() - lastCheck > 7200000) { // Paper - Lower to 2 hours
|
|
lastCheck = System.currentTimeMillis();
|
|
hasVersion = false;
|
|
} else {
|
|
@@ -180,24 +185,28 @@ public class VersionCommand extends BukkitCommand {
|
|
}
|
|
}
|
|
|
|
+ // Paper start
|
|
private void obtainVersion() {
|
|
String version = Bukkit.getVersion();
|
|
if (version == null) version = "Custom";
|
|
- if (version.startsWith("git-Spigot-")) {
|
|
- String[] parts = version.substring("git-Spigot-".length()).split("-");
|
|
- int cbVersions = getDistance("craftbukkit", parts[1].substring(0, parts[1].indexOf(' ')));
|
|
- int spigotVersions = getDistance("spigot", parts[0]);
|
|
- if (cbVersions == -1 || spigotVersions == -1) {
|
|
- setVersionMessage("Error obtaining version information");
|
|
- } else {
|
|
- if (cbVersions == 0 && spigotVersions == 0) {
|
|
+ if (version.startsWith("git-Paper-")) {
|
|
+ String[] parts = version.substring("git-Paper-".length()).split("[-\\s]");
|
|
+ int distance = getDistance(null, parts[0]);
|
|
+ switch (distance) {
|
|
+ case -1:
|
|
+ setVersionMessage("Error obtaining version information");
|
|
+ break;
|
|
+ case 0:
|
|
setVersionMessage("You are running the latest version");
|
|
- } else {
|
|
- setVersionMessage("You are " + (cbVersions + spigotVersions) + " version(s) behind");
|
|
- }
|
|
+ break;
|
|
+ case -2:
|
|
+ setVersionMessage("Unknown version");
|
|
+ break;
|
|
+ default:
|
|
+ setVersionMessage("You are " + distance + " version(s) behind");
|
|
}
|
|
-
|
|
} else if (version.startsWith("git-Bukkit-")) {
|
|
+ // Paper end
|
|
version = version.substring("git-Bukkit-".length());
|
|
int cbVersions = getDistance("craftbukkit", version.substring(0, version.indexOf(' ')));
|
|
if (cbVersions == -1) {
|
|
@@ -230,8 +239,16 @@ public class VersionCommand extends BukkitCommand {
|
|
}
|
|
}
|
|
|
|
- private static int getDistance(String repo, String hash) {
|
|
+ // Paper start
|
|
+ private static int getDistance(String repo, String verInfo) {
|
|
try {
|
|
+ int currentVer = Integer.decode(verInfo);
|
|
+ return getFromJenkins(currentVer);
|
|
+ } catch (NumberFormatException ex) {
|
|
+ verInfo = verInfo.replace("\"", "");
|
|
+ return getFromRepo("PaperMC/Paper", "master", verInfo);
|
|
+ }
|
|
+ /*
|
|
BufferedReader reader = Resources.asCharSource(
|
|
new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, "UTF-8") + "&withCounts=true"),
|
|
Charsets.UTF_8
|
|
@@ -245,9 +262,57 @@ public class VersionCommand extends BukkitCommand {
|
|
} finally {
|
|
reader.close();
|
|
}
|
|
+ */
|
|
+ }
|
|
+
|
|
+ private static int getFromJenkins(int currentVer) {
|
|
+ try {
|
|
+ BufferedReader reader = Resources.asCharSource(
|
|
+ new URL("https://ci.destroystokyo.com/job/Paper-1.13/lastSuccessfulBuild/buildNumber"), // Paper
|
|
+ Charsets.UTF_8
|
|
+ ).openBufferedStream();
|
|
+ try {
|
|
+ int newVer = Integer.decode(reader.readLine());
|
|
+ return newVer - currentVer;
|
|
+ } catch (NumberFormatException ex) {
|
|
+ ex.printStackTrace();
|
|
+ return -2;
|
|
+ } finally {
|
|
+ reader.close();
|
|
+ }
|
|
+ } catch (IOException e) {
|
|
+ e.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Contributed by Techcable <Techcable@outlook.com> in GH PR #65
|
|
+ private static int getFromRepo(String repo, String branch, 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 = (JSONObject) new JSONParser().parse(reader);
|
|
+ String status = (String) obj.get("status");
|
|
+ switch (status) {
|
|
+ case "identical":
|
|
+ return 0;
|
|
+ case "behind":
|
|
+ return ((Number) obj.get("behind_by")).intValue();
|
|
+ default:
|
|
+ return -1;
|
|
+ }
|
|
+ } catch (ParseException | NumberFormatException e) {
|
|
+ e.printStackTrace();
|
|
+ return -1;
|
|
+ }
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
return -1;
|
|
}
|
|
}
|
|
+ // Paper end
|
|
}
|
|
--
|
|
2.19.1
|
|
|