3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00

Add clickable version on version command (#9347)

Co-authored-by: Yannick Lamprecht <1420893+yannicklamprecht@users.noreply.github.com>
Dieser Commit ist enthalten in:
Phillipp Glanz 2023-08-06 03:26:13 +02:00 committet von GitHub
Ursprung 31358d5e48
Commit 8fe8ca6658
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 55 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -73,21 +73,24 @@ index f68ef89f37057cf677a767026ab395f7a839a2f9..a6aa33b9574d0278e10927007a62290e
// Paper end // Paper end
} }
diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c2f46935f 100644 index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b437cf212a63aa96a9492db8d01d5d37061aee23 100644
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java --- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
@@ -1,5 +1,6 @@ @@ -24,8 +24,25 @@ import org.bukkit.plugin.Plugin;
package org.bukkit.command.defaults; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.util.StringUtil;
+import com.destroystokyo.paper.util.VersionFetcher; // Paper - version supplier
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -26,6 +27,15 @@ import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
+// Paper start - version command 2.0
+import com.destroystokyo.paper.util.VersionFetcher;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.kyori.adventure.text.format.TextDecoration;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+// Paper end - version command 2.0
public class VersionCommand extends BukkitCommand { public class VersionCommand extends BukkitCommand {
+ private VersionFetcher versionFetcher; + private VersionFetcher versionFetcher; // Paper - version command 2.0
+ private VersionFetcher getVersionFetcher() { // lazy load because unsafe isn't available at command registration + private VersionFetcher getVersionFetcher() { // lazy load because unsafe isn't available at command registration
+ if (versionFetcher == null) { + if (versionFetcher == null) {
+ versionFetcher = Bukkit.getUnsafe().getVersionFetcher(); + versionFetcher = Bukkit.getUnsafe().getVersionFetcher();
@ -99,7 +102,7 @@ index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c
public VersionCommand(@NotNull String name) { public VersionCommand(@NotNull String name) {
super(name); super(name);
@@ -40,7 +50,7 @@ public class VersionCommand extends BukkitCommand { @@ -40,7 +57,7 @@ public class VersionCommand extends BukkitCommand {
if (!testPermission(sender)) return true; if (!testPermission(sender)) return true;
if (args.length == 0) { if (args.length == 0) {
@ -108,12 +111,32 @@ index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c
sendVersion(sender); sendVersion(sender);
} else { } else {
StringBuilder name = new StringBuilder(); StringBuilder name = new StringBuilder();
@@ -146,14 +156,14 @@ public class VersionCommand extends BukkitCommand { @@ -79,8 +96,17 @@ public class VersionCommand extends BukkitCommand {
private void describeToSender(@NotNull Plugin plugin, @NotNull CommandSender sender) {
PluginDescriptionFile desc = plugin.getDescription();
- sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
-
+ // Paper start - version command 2.0
+ sender.sendMessage(
+ Component.text()
+ .append(Component.text(desc.getName(), NamedTextColor.GREEN))
+ .append(Component.text(" version "))
+ .append(Component.text(desc.getVersion(), NamedTextColor.GREEN)
+ .hoverEvent(Component.text("Click to copy to clipboard", NamedTextColor.WHITE))
+ .clickEvent(ClickEvent.copyToClipboard(desc.getVersion()))
+ )
+ );
+ // Paper end - version command 2.0
if (desc.getDescription() != null) {
sender.sendMessage(desc.getDescription());
}
@@ -146,14 +172,14 @@ public class VersionCommand extends BukkitCommand {
private final ReentrantLock versionLock = new ReentrantLock(); private final ReentrantLock versionLock = new ReentrantLock();
private boolean hasVersion = false; private boolean hasVersion = false;
- private String versionMessage = null; - private String versionMessage = null;
+ private net.kyori.adventure.text.Component versionMessage = null; // Paper + private Component versionMessage = null; // Paper
private final Set<CommandSender> versionWaiters = new HashSet<CommandSender>(); private final Set<CommandSender> versionWaiters = new HashSet<CommandSender>();
private boolean versionTaskStarted = false; private boolean versionTaskStarted = false;
private long lastCheck = 0; private long lastCheck = 0;
@ -125,22 +148,22 @@ index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c
lastCheck = System.currentTimeMillis(); lastCheck = System.currentTimeMillis();
hasVersion = false; hasVersion = false;
} else { } else {
@@ -168,7 +178,7 @@ public class VersionCommand extends BukkitCommand { @@ -168,7 +194,7 @@ public class VersionCommand extends BukkitCommand {
return; return;
} }
versionWaiters.add(sender); versionWaiters.add(sender);
- sender.sendMessage("Checking version, please wait..."); - sender.sendMessage("Checking version, please wait...");
+ sender.sendMessage(net.kyori.adventure.text.Component.text("Checking version, please wait...", net.kyori.adventure.text.format.NamedTextColor.WHITE, net.kyori.adventure.text.format.TextDecoration.ITALIC)); // Paper + sender.sendMessage(Component.text("Checking version, please wait...", NamedTextColor.WHITE, TextDecoration.ITALIC)); // Paper
if (!versionTaskStarted) { if (!versionTaskStarted) {
versionTaskStarted = true; versionTaskStarted = true;
new Thread(new Runnable() { new Thread(new Runnable() {
@@ -186,6 +196,13 @@ public class VersionCommand extends BukkitCommand { @@ -186,6 +212,13 @@ public class VersionCommand extends BukkitCommand {
private void obtainVersion() { private void obtainVersion() {
String version = Bukkit.getVersion(); String version = Bukkit.getVersion();
+ // Paper start + // Paper start
+ if (version.startsWith("null")) { // running from ide? + if (version.startsWith("null")) { // running from ide?
+ setVersionMessage(net.kyori.adventure.text.Component.text("Unknown version, custom build?", net.kyori.adventure.text.format.NamedTextColor.YELLOW)); + setVersionMessage(Component.text("Unknown version, custom build?", NamedTextColor.YELLOW));
+ return; + return;
+ } + }
+ setVersionMessage(getVersionFetcher().getVersionMessage(version)); + setVersionMessage(getVersionFetcher().getVersionMessage(version));
@ -148,7 +171,7 @@ index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c
if (version == null) version = "Custom"; if (version == null) version = "Custom";
String[] parts = version.substring(0, version.indexOf(' ')).split("-"); String[] parts = version.substring(0, version.indexOf(' ')).split("-");
if (parts.length == 4) { if (parts.length == 4) {
@@ -215,11 +232,24 @@ public class VersionCommand extends BukkitCommand { @@ -215,11 +248,24 @@ public class VersionCommand extends BukkitCommand {
} else { } else {
setVersionMessage("Unknown version, custom build?"); setVersionMessage("Unknown version, custom build?");
} }
@ -158,18 +181,18 @@ index 04b4fb6859df0221f8f9f92c5a7ac2dda1073355..b50f614806f4634960d383e8a33f094c
- private void setVersionMessage(@NotNull String msg) { - private void setVersionMessage(@NotNull String msg) {
+ // Paper start + // Paper start
+ private void setVersionMessage(final @NotNull net.kyori.adventure.text.Component msg) { + private void setVersionMessage(final @NotNull Component msg) {
lastCheck = System.currentTimeMillis(); lastCheck = System.currentTimeMillis();
- versionMessage = msg; - versionMessage = msg;
+ final net.kyori.adventure.text.Component message = net.kyori.adventure.text.TextComponent.ofChildren( + final Component message = Component.textOfChildren(
+ net.kyori.adventure.text.Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", net.kyori.adventure.text.format.NamedTextColor.WHITE), + Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", NamedTextColor.WHITE),
+ net.kyori.adventure.text.Component.newline(), + Component.newline(),
+ msg + msg
+ ); + );
+ this.versionMessage = net.kyori.adventure.text.Component.text() + this.versionMessage = Component.text()
+ .append(message) + .append(message)
+ .hoverEvent(net.kyori.adventure.text.Component.text("Click to copy to clipboard", net.kyori.adventure.text.format.NamedTextColor.WHITE)) + .hoverEvent(Component.text("Click to copy to clipboard", NamedTextColor.WHITE))
+ .clickEvent(net.kyori.adventure.text.event.ClickEvent.copyToClipboard(net.kyori.adventure.text.serializer.plain.PlainComponentSerializer.plain().serialize(message))) + .clickEvent(ClickEvent.copyToClipboard(PlainTextComponentSerializer.plainText().serialize(message)))
+ .build(); + .build();
+ // Paper end + // Paper end
versionLock.lock(); versionLock.lock();

Datei anzeigen

@ -87,15 +87,15 @@ index 67c92e10b38af2ac45c1d9b6374695247bf1e7c3..627c04f5e71ad032760296092a65596b
/** /**
diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
index b50f614806f4634960d383e8a33f094c2f46935f..e40f017f87d6b6b4770501b106c76dc69ec69abb 100644 index b437cf212a63aa96a9492db8d01d5d37061aee23..fd5d9881abfd930bb883120f018f76dc78b62b14 100644
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java --- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
@@ -240,7 +240,7 @@ public class VersionCommand extends BukkitCommand { @@ -256,7 +256,7 @@ public class VersionCommand extends BukkitCommand {
private void setVersionMessage(final @NotNull net.kyori.adventure.text.Component msg) { private void setVersionMessage(final @NotNull Component msg) {
lastCheck = System.currentTimeMillis(); lastCheck = System.currentTimeMillis();
final net.kyori.adventure.text.Component message = net.kyori.adventure.text.TextComponent.ofChildren( final Component message = Component.textOfChildren(
- net.kyori.adventure.text.Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", net.kyori.adventure.text.format.NamedTextColor.WHITE), - Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", NamedTextColor.WHITE),
+ net.kyori.adventure.text.Component.text(Bukkit.getVersionMessage(), net.kyori.adventure.text.format.NamedTextColor.WHITE), + Component.text(Bukkit.getVersionMessage(), NamedTextColor.WHITE),
net.kyori.adventure.text.Component.newline(), Component.newline(),
msg msg
); );