Use Adventure for /version command feedback, add copy to clipboard click event (#5333)

This commit is contained in:
Jason Penilla
2021-03-09 20:56:13 -08:00
parent f33a17faf7
commit e59776a02e
3 changed files with 82 additions and 61 deletions

View File

@@ -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

View File

@@ -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);
+ }
+ }
+