2019-08-05 18:35:40 +02:00
|
|
|
From eff79b832f995fb9394e5d7a749db0fbde4999fb Mon Sep 17 00:00:00 2001
|
2018-03-02 02:57:22 +01:00
|
|
|
From: Kyle Wood <demonwav@gmail.com>
|
|
|
|
Date: Thu, 1 Mar 2018 19:37:52 -0600
|
|
|
|
Subject: [PATCH] Add version history to version command
|
|
|
|
|
|
|
|
|
2019-05-27 11:13:41 +02:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
2019-06-06 17:36:57 +02:00
|
|
|
index ded51d042b..513cddb9bd 100644
|
2019-05-27 11:13:41 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
2019-05-31 01:31:48 +02:00
|
|
|
@@ -25,7 +25,10 @@ public class PaperVersionFetcher implements VersionFetcher {
|
2019-05-27 11:13:41 +02:00
|
|
|
@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]);
|
|
|
|
+ String updateMessage = getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]);
|
2019-05-31 01:31:48 +02:00
|
|
|
+ String history = getHistory();
|
2019-05-27 11:13:41 +02:00
|
|
|
+
|
2019-05-31 01:31:48 +02:00
|
|
|
+ return history != null ? history + "\n" + updateMessage : updateMessage;
|
2019-05-27 11:13:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static @Nullable String getMinecraftVersion() {
|
2019-05-31 01:31:48 +02:00
|
|
|
@@ -112,4 +115,19 @@ public class PaperVersionFetcher implements VersionFetcher {
|
2019-05-27 11:13:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ private String getHistory() {
|
|
|
|
+ final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
|
|
|
|
+ if (data == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final String oldVersion = data.getOldVersion();
|
|
|
|
+ if (oldVersion == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return "Previous version: " + oldVersion;
|
|
|
|
+ }
|
|
|
|
}
|
2018-03-02 02:57:22 +01:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java b/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java
|
|
|
|
new file mode 100644
|
2019-06-06 17:36:57 +02:00
|
|
|
index 0000000000..aac3f66cb2
|
2018-03-02 02:57:22 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java
|
2019-05-27 11:13:41 +02:00
|
|
|
@@ -0,0 +1,145 @@
|
2018-03-02 02:57:22 +01:00
|
|
|
+package com.destroystokyo.paper;
|
|
|
|
+
|
|
|
|
+import com.google.common.base.MoreObjects;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.google.gson.JsonSyntaxException;
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.BufferedWriter;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.nio.file.StandardOpenOption;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.logging.Level;
|
|
|
|
+import java.util.logging.Logger;
|
|
|
|
+import org.bukkit.Bukkit;
|
2019-05-27 11:13:41 +02:00
|
|
|
+
|
|
|
|
+import javax.annotation.Nonnull;
|
|
|
|
+import javax.annotation.Nullable;
|
2018-03-02 02:57:22 +01:00
|
|
|
+
|
|
|
|
+public enum VersionHistoryManager {
|
|
|
|
+ INSTANCE;
|
|
|
|
+
|
|
|
|
+ private final Gson gson = new Gson();
|
|
|
|
+
|
|
|
|
+ private final Logger logger = Bukkit.getLogger();
|
|
|
|
+
|
|
|
|
+ private VersionData currentData = null;
|
|
|
|
+
|
|
|
|
+ VersionHistoryManager() {
|
|
|
|
+ final Path path = Paths.get("version_history.json");
|
|
|
|
+
|
|
|
|
+ if (Files.exists(path)) {
|
|
|
|
+ // Basic file santiy checks
|
|
|
|
+ if (!Files.isRegularFile(path)) {
|
|
|
|
+ if (Files.isDirectory(path)) {
|
|
|
|
+ logger.severe(path + " is a directory, cannot be used for version history");
|
|
|
|
+ } else {
|
|
|
|
+ logger.severe(path + " is not a regular file, cannot be used for version history");
|
|
|
|
+ }
|
|
|
|
+ // We can't continue
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try (final BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
|
|
|
|
+ currentData = gson.fromJson(reader, VersionData.class);
|
|
|
|
+ } catch (final IOException e) {
|
|
|
|
+ logger.log(Level.SEVERE, "Failed to read version history file '" + path + "'", e);
|
|
|
|
+ return;
|
|
|
|
+ } catch (final JsonSyntaxException e) {
|
|
|
|
+ logger.log(Level.SEVERE, "Invalid json syntax for file '" + path + "'", e);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final String version = Bukkit.getVersion();
|
|
|
|
+ if (version == null) {
|
|
|
|
+ logger.severe("Failed to retrieve current version");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!version.equals(currentData.getCurrentVersion())) {
|
|
|
|
+ // The version appears to have changed
|
|
|
|
+ currentData.setOldVersion(currentData.getCurrentVersion());
|
|
|
|
+ currentData.setCurrentVersion(version);
|
|
|
|
+ writeFile(path);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // File doesn't exist, start fresh
|
|
|
|
+ currentData = new VersionData();
|
|
|
|
+ // oldVersion is null
|
|
|
|
+ currentData.setCurrentVersion(Bukkit.getVersion());
|
|
|
|
+ writeFile(path);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2019-05-27 11:13:41 +02:00
|
|
|
+ private void writeFile(@Nonnull final Path path) {
|
2018-03-02 02:57:22 +01:00
|
|
|
+ try (final BufferedWriter writer = Files.newBufferedWriter(
|
|
|
|
+ path,
|
|
|
|
+ StandardCharsets.UTF_8,
|
|
|
|
+ StandardOpenOption.WRITE,
|
|
|
|
+ StandardOpenOption.CREATE,
|
|
|
|
+ StandardOpenOption.TRUNCATE_EXISTING
|
|
|
|
+ )) {
|
|
|
|
+ gson.toJson(currentData, writer);
|
|
|
|
+ } catch (final IOException e) {
|
|
|
|
+ logger.log(Level.SEVERE, "Failed to write to version history file", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public VersionData getVersionData() {
|
|
|
|
+ return currentData;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public static class VersionData {
|
2018-03-02 02:57:22 +01:00
|
|
|
+ private String oldVersion;
|
|
|
|
+
|
|
|
|
+ private String currentVersion;
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public String getOldVersion() {
|
|
|
|
+ return oldVersion;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setOldVersion(@Nullable String oldVersion) {
|
|
|
|
+ this.oldVersion = oldVersion;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public String getCurrentVersion() {
|
|
|
|
+ return currentVersion;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setCurrentVersion(@Nullable String currentVersion) {
|
|
|
|
+ this.currentVersion = currentVersion;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return MoreObjects.toStringHelper(this)
|
|
|
|
+ .add("oldVersion", oldVersion)
|
|
|
|
+ .add("currentVersion", currentVersion)
|
|
|
|
+ .toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public boolean equals(@Nullable Object o) {
|
2018-03-02 02:57:22 +01:00
|
|
|
+ if (this == o) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (o == null || getClass() != o.getClass()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ final VersionData versionData = (VersionData) o;
|
|
|
|
+ return Objects.equals(oldVersion, versionData.oldVersion) &&
|
|
|
|
+ Objects.equals(currentVersion, versionData.currentVersion);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ return Objects.hash(oldVersion, currentVersion);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
2019-05-27 11:13:41 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2019-08-05 18:35:40 +02:00
|
|
|
index ce3ca4830e..895049287c 100644
|
2019-05-27 11:13:41 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2019-08-05 18:35:40 +02:00
|
|
|
@@ -172,6 +172,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
2019-05-27 11:13:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
com.destroystokyo.paper.PaperConfig.registerCommands();
|
|
|
|
+ com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
|
|
|
|
// Paper end
|
2018-03-02 02:57:22 +01:00
|
|
|
|
2019-05-27 11:13:41 +02:00
|
|
|
this.setSpawnAnimals(dedicatedserverproperties.spawnAnimals);
|
2018-03-02 02:57:22 +01:00
|
|
|
--
|
2019-06-25 03:47:58 +02:00
|
|
|
2.22.0
|
2018-03-02 02:57:22 +01:00
|
|
|
|