mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 12:11:47 +01:00
01a13871de
Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
214 lines
8.1 KiB
Diff
214 lines
8.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Kyle Wood <kyle@denwav.dev>
|
|
Date: Thu, 1 Mar 2018 19:37:52 -0600
|
|
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 351159bbdb0c8045f4983f54dee34430dbcc423e..bf42969859545a8a520923ef1836ffa4a5cc24a0 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
|
@@ -7,6 +7,8 @@ import com.google.gson.*;
|
|
import net.kyori.adventure.text.Component;
|
|
import net.kyori.adventure.text.event.ClickEvent;
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.TextComponent;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import javax.annotation.Nullable;
|
|
@@ -30,7 +32,10 @@ public class PaperVersionFetcher implements VersionFetcher {
|
|
@Override
|
|
public Component getVersionMessage(@Nonnull String serverVersion) {
|
|
String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]");
|
|
- return getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]);
|
|
+ final Component updateMessage = getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]);
|
|
+ final Component history = getHistory();
|
|
+
|
|
+ return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage;
|
|
}
|
|
|
|
private static @Nullable String getMinecraftVersion() {
|
|
@@ -126,4 +131,19 @@ public class PaperVersionFetcher implements VersionFetcher {
|
|
return -1;
|
|
}
|
|
}
|
|
+
|
|
+ @Nullable
|
|
+ private Component getHistory() {
|
|
+ final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
|
|
+ if (data == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ final String oldVersion = data.getOldVersion();
|
|
+ if (oldVersion == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return Component.text("Previous version: " + oldVersion, NamedTextColor.GRAY, TextDecoration.ITALIC);
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java b/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..aac3f66cb23d260729c2a48d8710a9de2346aa22
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/VersionHistoryManager.java
|
|
@@ -0,0 +1,145 @@
|
|
+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;
|
|
+
|
|
+import javax.annotation.Nonnull;
|
|
+import javax.annotation.Nullable;
|
|
+
|
|
+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);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void writeFile(@Nonnull final Path path) {
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ public static class VersionData {
|
|
+ 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
|
|
+ public boolean equals(@Nullable Object o) {
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index fa1ab9974859c75075f3090e36e0de58dda3e8e6..4dc5a5888f0180e1490597e43956e8e80981f8b9 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -194,6 +194,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
paperConfigurations.initializeWorldDefaultsConfiguration();
|
|
io.papermc.paper.command.PaperCommands.registerCommands(this);
|
|
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics();
|
|
+ com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
|
|
// Paper end
|
|
|
|
this.setPvpAllowed(dedicatedserverproperties.pvp);
|