2016-02-15 15:31:45 +01:00
|
|
|
From 386d76f2e47c4d3e3b824d6ec2c25d914fbe6e2c Mon Sep 17 00:00:00 2001
|
2014-12-28 00:21:50 +01:00
|
|
|
From: Zach Brown <Zbob750@live.com>
|
2014-12-28 23:37:21 +01:00
|
|
|
Date: Sun, 28 Dec 2014 16:28:21 -0600
|
2014-12-28 00:21:50 +01:00
|
|
|
Subject: [PATCH] Check PaperSpigot versions
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
2016-02-15 15:31:45 +01:00
|
|
|
index b55abdb..e91e1d8 100644
|
2014-12-28 00:21:50 +01:00
|
|
|
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
|
|
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
2016-02-15 13:02:47 +01:00
|
|
|
@@ -185,7 +185,21 @@ public class VersionCommand extends BukkitCommand {
|
2014-12-28 00:21:50 +01:00
|
|
|
private void obtainVersion() {
|
|
|
|
String version = Bukkit.getVersion();
|
|
|
|
if (version == null) version = "Custom";
|
|
|
|
- if (version.startsWith("git-Spigot-")) {
|
2014-12-28 23:37:21 +01:00
|
|
|
+ // PaperSpigot start
|
2014-12-28 00:21:50 +01:00
|
|
|
+ if (version.startsWith("git-PaperSpigot-")) {
|
2016-02-15 13:02:47 +01:00
|
|
|
+ String[] parts = version.substring("git-PaperSpigot-".length()).split("[-\\s]");
|
2014-12-28 00:21:50 +01:00
|
|
|
+ int paperSpigotVersions = getDistance("paperspigot", parts[0]);
|
2016-02-15 13:02:47 +01:00
|
|
|
+ if (paperSpigotVersions == -1) {
|
2014-12-28 00:21:50 +01:00
|
|
|
+ setVersionMessage("Error obtaining version information");
|
2014-12-28 23:37:21 +01:00
|
|
|
+ } else {
|
2016-02-15 13:02:47 +01:00
|
|
|
+ if (paperSpigotVersions == 0) {
|
2014-12-28 00:21:50 +01:00
|
|
|
+ setVersionMessage("You are running the latest version");
|
2014-12-28 23:37:21 +01:00
|
|
|
+ } else {
|
2016-02-15 13:02:47 +01:00
|
|
|
+ setVersionMessage("You are " + paperSpigotVersions + " version(s) behind");
|
2014-12-28 00:21:50 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (version.startsWith("git-Spigot-")) {
|
|
|
|
+ // PaperSpigot end
|
|
|
|
String[] parts = version.substring("git-Spigot-".length()).split("-");
|
2014-12-28 23:37:21 +01:00
|
|
|
int cbVersions = getDistance("craftbukkit", parts[1].substring(0, parts[1].indexOf(' ')));
|
2014-12-28 00:21:50 +01:00
|
|
|
int spigotVersions = getDistance("spigot", parts[0]);
|
2016-02-15 15:31:45 +01:00
|
|
|
@@ -232,17 +246,20 @@ public class VersionCommand extends BukkitCommand {
|
2016-02-15 13:02:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- private static int getDistance(String repo, String hash) {
|
|
|
|
+ private static int getDistance(String repo, String currentVerInt) { // PaperSpigot
|
2014-12-28 00:21:50 +01:00
|
|
|
try {
|
|
|
|
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"),
|
2016-02-15 13:02:47 +01:00
|
|
|
+ new URL("https://ci.destroystokyo.com/job/PaperSpigot/lastSuccessfulBuild/buildNumber"), // PaperSpigot
|
2014-12-28 00:21:50 +01:00
|
|
|
Charsets.UTF_8
|
|
|
|
).openBufferedStream();
|
|
|
|
try {
|
2016-02-15 13:02:47 +01:00
|
|
|
- JSONObject obj = (JSONObject) new JSONParser().parse(reader);
|
|
|
|
- return ((Number) obj.get("totalCount")).intValue();
|
|
|
|
- } catch (ParseException ex) {
|
2016-02-15 15:31:45 +01:00
|
|
|
- ex.printStackTrace();
|
2016-02-15 13:02:47 +01:00
|
|
|
+ // PaperSpigot start
|
|
|
|
+ int newVer = Integer.decode(reader.readLine());
|
|
|
|
+ int currentVer = Integer.decode(currentVerInt);
|
|
|
|
+ return newVer - currentVer;
|
|
|
|
+ } catch (NumberFormatException ex) {
|
2016-02-15 15:31:45 +01:00
|
|
|
+ //ex.printStackTrace();
|
2016-02-15 13:02:47 +01:00
|
|
|
+ // PaperSpigot end
|
|
|
|
return -1;
|
|
|
|
} finally {
|
2016-02-15 15:31:45 +01:00
|
|
|
reader.close();
|
2014-12-28 00:21:50 +01:00
|
|
|
--
|
2016-02-15 13:02:47 +01:00
|
|
|
2.7.1
|
2014-12-28 00:21:50 +01:00
|
|
|
|