diff --git a/Spigot-API-Patches/Version-Command-2.0.patch b/Spigot-API-Patches/Version-Command-2.0.patch index 2b3c93ca16..4977e0baa5 100644 --- a/Spigot-API-Patches/Version-Command-2.0.patch +++ b/Spigot-API-Patches/Version-Command-2.0.patch @@ -12,6 +12,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package com.destroystokyo.paper.util; + ++import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + @@ -26,16 +28,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + long getCacheTime(); + + /** -+ * Gets the version message to cache and show to command senders. Multiple messages can be sent using newlines (\n) -+ * in the string. The string will be split on these newlines and sent as individual messages. -+ *

-+ * NOTE: This is run in a new thread separate from that of the command processing thread ++ * Gets the version message to cache and show to command senders. ++ * ++ *

NOTE: This is run in a new thread separate from that of the command processing thread

+ * + * @param serverVersion the current version of the server (will match {@link Bukkit#getVersion()}) + * @return the message to show when requesting a version + */ + @NotNull -+ String getVersionMessage(@NotNull String serverVersion); ++ Component getVersionMessage(@NotNull String serverVersion); + + class DummyVersionFetcher implements VersionFetcher { + @@ -46,11 +47,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @NotNull + @Override -+ public String getVersionMessage(@NotNull String serverVersion) { ++ public Component getVersionMessage(@NotNull String serverVersion) { + Bukkit.getLogger().warning("Version provider has not been set, cannot check for updates!"); + Bukkit.getLogger().info("Override the default implementation of org.bukkit.UnsafeValues#getVersionFetcher()"); + new Throwable().printStackTrace(); -+ return "Unable to check for updates. No version provider set."; ++ return Component.text("Unable to check for updates. No version provider set.", NamedTextColor.RED); + } + } +} @@ -82,6 +83,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; +@@ -0,0 +0,0 @@ import java.util.HashSet; + import java.util.List; + import java.util.Set; + import java.util.concurrent.locks.ReentrantLock; ++import net.kyori.adventure.text.Component; // Paper + import org.apache.commons.lang.Validate; + import org.bukkit.Bukkit; + import org.bukkit.ChatColor; @@ -0,0 +0,0 @@ import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -99,6 +108,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 super(name); @@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { + if (!testPermission(sender)) return true; + + if (args.length == 0) { +- sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")"); ++ //sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")"); // Paper - moved to setVersionMessage + sendVersion(sender); + } else { + StringBuilder name = new StringBuilder(); +@@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { + + private final ReentrantLock versionLock = new ReentrantLock(); + private boolean hasVersion = false; +- private String versionMessage = null; ++ private Component versionMessage = null; // Paper + private final Set versionWaiters = new HashSet(); + private boolean versionTaskStarted = false; + private long lastCheck = 0; private void sendVersion(@NotNull CommandSender sender) { if (hasVersion) { @@ -107,28 +133,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 lastCheck = System.currentTimeMillis(); hasVersion = false; } else { -- sender.sendMessage(versionMessage); -+ sendMessages(versionMessage, sender); // Paper - allow \n for multiple messages - return; - } - } - versionLock.lock(); - try { - if (hasVersion) { -- sender.sendMessage(versionMessage); -+ sendMessages(versionMessage, sender); // Paper - allow \n for multiple messages +@@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { return; } versionWaiters.add(sender); +- sender.sendMessage("Checking version, please wait..."); ++ sender.sendMessage(Component.text("Checking version, please wait...", net.kyori.adventure.text.format.NamedTextColor.WHITE, net.kyori.adventure.text.format.TextDecoration.ITALIC)); // Paper + if (!versionTaskStarted) { + versionTaskStarted = true; + new Thread(new Runnable() { @@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { private void obtainVersion() { String version = Bukkit.getVersion(); + // Paper start + if (version.startsWith("null")) { // running from ide? -+ setVersionMessage("Unknown version, custom build?"); ++ setVersionMessage(Component.text("Unknown version, custom build?", net.kyori.adventure.text.format.NamedTextColor.YELLOW)); + return; + } ++ setVersionMessage(getVersionFetcher().getVersionMessage(version)); + /* if (version == null) version = "Custom"; String[] parts = version.substring(0, version.indexOf(' ')).split("-"); @@ -138,39 +161,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 setVersionMessage("Unknown version, custom build?"); } + */ -+ setVersionMessage(getVersionFetcher().getVersionMessage(version)); + // Paper end } - private void setVersionMessage(@NotNull String msg) { -@@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { +- private void setVersionMessage(@NotNull String msg) { ++ // Paper start ++ private void setVersionMessage(final @NotNull Component msg) { + lastCheck = System.currentTimeMillis(); +- versionMessage = msg; ++ final Component message = net.kyori.adventure.text.TextComponent.ofChildren( ++ Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", net.kyori.adventure.text.format.NamedTextColor.WHITE), ++ Component.newline(), ++ msg ++ ); ++ this.versionMessage = Component.text() ++ .append(message) ++ .hoverEvent(Component.text("Click to copy to clipboard", net.kyori.adventure.text.format.NamedTextColor.WHITE)) ++ .clickEvent(net.kyori.adventure.text.event.ClickEvent.copyToClipboard(net.kyori.adventure.text.serializer.plain.PlainComponentSerializer.plain().serialize(message))) ++ .build(); ++ // Paper end + versionLock.lock(); try { hasVersion = true; - versionTaskStarted = false; -+ // Paper - allow \n for multiple messages -+ String[] messages = versionMessage.split("\n"); - for (CommandSender sender : versionWaiters) { -- sender.sendMessage(versionMessage); -+ for (String message : messages) { -+ sender.sendMessage(message); -+ } -+ // Paper end - } - versionWaiters.clear(); - } finally { -@@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { - } - } - -+ // Paper start -+ private void sendMessages(String toSplit, CommandSender target) { -+ String[] messages = toSplit.split("\n"); -+ for (String message : messages) { -+ target.sendMessage(message); -+ } -+ } -+ // Paper end -+ - private static int getDistance(@NotNull String repo, @NotNull String hash) { - try { - BufferedReader reader = Resources.asCharSource( diff --git a/Spigot-Server-Patches/Add-version-history-to-version-command.patch b/Spigot-Server-Patches/Add-version-history-to-version-command.patch index 1ca4d68f82..30dc2771ea 100644 --- a/Spigot-Server-Patches/Add-version-history-to-version-command.patch +++ b/Spigot-Server-Patches/Add-version-history-to-version-command.patch @@ -8,15 +8,25 @@ diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/sr index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java +++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java +@@ -0,0 +0,0 @@ import com.google.common.base.Charsets; + import com.google.common.io.Resources; + import com.google.gson.*; + import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.TextComponent; + import net.kyori.adventure.text.format.NamedTextColor; ++import net.kyori.adventure.text.format.TextDecoration; + + import javax.annotation.Nonnull; + import javax.annotation.Nullable; @@ -0,0 +0,0 @@ public class PaperVersionFetcher implements VersionFetcher { @Override - public String getVersionMessage(@Nonnull String serverVersion) { + public Component 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]); -+ String history = getHistory(); ++ final Component updateMessage = getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]); ++ final Component history = getHistory(); + -+ return history != null ? history + "\n" + updateMessage : updateMessage; ++ return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage; } private static @Nullable String getMinecraftVersion() { @@ -26,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + + @Nullable -+ private String getHistory() { ++ private Component getHistory() { + final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData(); + if (data == null) { + return null; @@ -37,7 +47,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return null; + } + -+ return "Previous version: " + oldVersion; ++ 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 diff --git a/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch b/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch index 304fa94eb3..a88268bc29 100644 --- a/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch +++ b/Spigot-Server-Patches/Implement-Paper-VersionChecker.patch @@ -16,6 +16,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import com.google.gson.*; ++import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.format.NamedTextColor; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; @@ -35,7 +37,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Nonnull + @Override -+ public String getVersionMessage(@Nonnull String serverVersion) { ++ public Component getVersionMessage(@Nonnull String serverVersion) { + String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]"); + return getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]); + } @@ -56,7 +58,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return mcVer; + } + -+ private static String getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) { ++ private static Component getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) { + int distance; + try { + int jenkinsBuild = Integer.parseInt(versionInfo); @@ -68,13 +70,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + switch (distance) { + case -1: -+ return "Error obtaining version information"; ++ return Component.text("Error obtaining version information", NamedTextColor.YELLOW); + case 0: -+ return "You are running the latest version"; ++ return Component.text("You are running the latest version", NamedTextColor.GREEN); + case -2: -+ return "Unknown version"; ++ return Component.text("Unknown version", NamedTextColor.YELLOW); + default: -+ return "You are " + distance + " version(s) behind"; ++ return Component.text("You are " + distance + " version(s) behind", NamedTextColor.YELLOW); + } + } +