mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-09-18 21:33:01 +00:00
#98: Improve output of /plugins command using text components
This commit is contained in:
parent
732d5bab9d
commit
1a27cfd8cc
1 changed files with 118 additions and 0 deletions
118
Bukkit-Patches/0016-Improve-output-of-plugins-command.patch
Normal file
118
Bukkit-Patches/0016-Improve-output-of-plugins-command.patch
Normal file
|
@ -0,0 +1,118 @@
|
|||
From 3206eea0b5b78c8fce6459f70c2c8c6a7f123824 Mon Sep 17 00:00:00 2001
|
||||
From: Parker Hawke <hawkeboyz2@hotmail.com>
|
||||
Date: Sat, 27 Jun 2020 18:43:37 -0400
|
||||
Subject: [PATCH] Improve output of plugins command
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/command/defaults/PluginsCommand.java b/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
|
||||
index bcb576a4..23a8a861 100644
|
||||
--- a/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
|
||||
+++ b/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
|
||||
@@ -8,6 +8,15 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
+// Spigot start
|
||||
+import net.md_5.bungee.api.chat.BaseComponent;
|
||||
+import net.md_5.bungee.api.chat.ClickEvent;
|
||||
+import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
+import net.md_5.bungee.api.chat.HoverEvent;
|
||||
+import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.plugin.PluginDescriptionFile;
|
||||
+// Spigot end
|
||||
|
||||
public class PluginsCommand extends BukkitCommand {
|
||||
public PluginsCommand(@NotNull String name) {
|
||||
@@ -22,7 +31,13 @@ public class PluginsCommand extends BukkitCommand {
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
- sender.sendMessage("Plugins " + getPluginList());
|
||||
+ // Spigot start
|
||||
+ if (sender instanceof Player && sender.hasPermission("bukkit.command.version")) {
|
||||
+ sender.spigot().sendMessage(getPluginListSpigot());
|
||||
+ } else {
|
||||
+ sender.sendMessage("Plugins " + getPluginList());
|
||||
+ }
|
||||
+ // Spigot end
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,4 +68,73 @@ public class PluginsCommand extends BukkitCommand {
|
||||
|
||||
return "(" + plugins.length + "): " + pluginList.toString();
|
||||
}
|
||||
+
|
||||
+ // Spigot start
|
||||
+ @NotNull
|
||||
+ private BaseComponent[] getPluginListSpigot() {
|
||||
+ Plugin[] plugins = Bukkit.getPluginManager().getPlugins();
|
||||
+ ComponentBuilder pluginList = new ComponentBuilder("Plugins (" + plugins.length + "): ");
|
||||
+
|
||||
+ int index = 0;
|
||||
+ for (Plugin plugin : plugins) {
|
||||
+ if (index++ > 0) {
|
||||
+ pluginList.append(", ", FormatRetention.NONE).color(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
+ }
|
||||
+
|
||||
+ // Event components
|
||||
+ PluginDescriptionFile description = plugin.getDescription();
|
||||
+ ComponentBuilder hoverEventComponents = new ComponentBuilder();
|
||||
+ hoverEventComponents.append("Version: ").color(net.md_5.bungee.api.ChatColor.WHITE).append(description.getVersion()).color(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
+
|
||||
+ if (description.getDescription() != null) {
|
||||
+ hoverEventComponents.append("\nDescription: ").color(net.md_5.bungee.api.ChatColor.WHITE).append(description.getDescription()).color(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
+ }
|
||||
+
|
||||
+ if (description.getWebsite() != null) {
|
||||
+ hoverEventComponents.append("\nWebsite: ").color(net.md_5.bungee.api.ChatColor.WHITE).append(description.getVersion()).color(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
+ }
|
||||
+
|
||||
+ if (!description.getAuthors().isEmpty()) {
|
||||
+ if (description.getAuthors().size() == 1) {
|
||||
+ hoverEventComponents.append("\nAuthor: ");
|
||||
+ } else {
|
||||
+ hoverEventComponents.append("\nAuthors: ");
|
||||
+ }
|
||||
+
|
||||
+ hoverEventComponents.color(net.md_5.bungee.api.ChatColor.WHITE).append(getAuthors(description));
|
||||
+ }
|
||||
+
|
||||
+ HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverEventComponents.create());
|
||||
+ ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/version " + description.getName());
|
||||
+
|
||||
+ // Plugin list entry
|
||||
+ pluginList.append(plugin.getDescription().getName());
|
||||
+ pluginList.color(plugin.isEnabled() ? net.md_5.bungee.api.ChatColor.GREEN : net.md_5.bungee.api.ChatColor.RED);
|
||||
+ pluginList.event(hoverEvent).event(clickEvent);
|
||||
+
|
||||
+ if (plugin.getDescription().getProvides().size() > 0) {
|
||||
+ pluginList.append("( ", FormatRetention.NONE).color(net.md_5.bungee.api.ChatColor.WHITE).append(String.join(", ", plugin.getDescription().getProvides())).append(")");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return pluginList.create();
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ private BaseComponent[] getAuthors(@NotNull final PluginDescriptionFile description) {
|
||||
+ ComponentBuilder result = new ComponentBuilder();
|
||||
+ List<String> authors = description.getAuthors();
|
||||
+
|
||||
+ for (int i = 0; i < authors.size(); i++) {
|
||||
+ if (i > 0) {
|
||||
+ result.append(i < authors.size() - 1 ? ", " : " and ", FormatRetention.NONE);
|
||||
+ result.color(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
+ }
|
||||
+
|
||||
+ result.append(authors.get(i)).color(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
+ }
|
||||
+
|
||||
+ return result.create();
|
||||
+ }
|
||||
+ // Spigot end
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
Loading…
Add table
Reference in a new issue