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

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