-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path0009-Improved-plugins-command.patch
141 lines (135 loc) · 5.93 KB
/
0009-Improved-plugins-command.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hpfxd <[email protected]>
Date: Thu, 4 Nov 2021 10:38:49 -0400
Subject: [PATCH] Improved plugins command
This patch modifies /plugins to add the ability for players to hover
over plugins to view additional information. If this command is not
executed by a player, it will fall back to the normal message.
Additionally, if the sender has permission to use /version, clicking
on a plugin will execute "/version <plugin name>"
diff --git a/src/main/java/org/bukkit/command/defaults/PluginsCommand.java b/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
index e21d16793b703189a5f4cf9091ac12f494d0107e..6f2eef45b72dc68668aa214cc21a08997b477eb5 100644
--- a/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/PluginsCommand.java
@@ -6,6 +6,15 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
+// PandaSpigot start - Improved plugins command
+import java.util.TreeMap;
+import net.md_5.bungee.api.chat.ComponentBuilder;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.ClickEvent;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.entity.Player;
+// PandaSpigot end
public class PluginsCommand extends BukkitCommand {
public PluginsCommand(String name) {
@@ -20,10 +29,108 @@ public class PluginsCommand extends BukkitCommand {
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
+ // PandaSpigot start - Improved plugins command
+ if (sender instanceof Player) {
+ ((Player) sender).sendMessage(this.getPluginListComponents(sender.hasPermission("bukkit.command.version")));
+ return true;
+ }
+ // PandaSpigot end
sender.sendMessage("Plugins " + getPluginList());
return true;
}
+ // PandaSpigot start - Improved plugins command
+ /**
+ * Formats the plugin list to be sent to a player.
+ *
+ * @param versionCommand Whether the sender has permission to use "/version".
+ * @return The resulting components.
+ */
+ private BaseComponent[] getPluginListComponents(boolean versionCommand) {
+ // Use a TreeMap for sorting
+ TreeMap<String, Plugin> plugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+
+ for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
+ plugins.put(plugin.getDescription().getName(), plugin);
+ }
+
+ ComponentBuilder builder = new ComponentBuilder("Plugins (" + plugins.size() + "): ");
+
+ java.util.List<Plugin> values = new java.util.ArrayList<>(plugins.values());
+ for (int i = 0; i < values.size(); i++) {
+ Plugin plugin = values.get(i);
+ PluginDescriptionFile description = plugin.getDescription();
+
+ builder
+ .append(description.getName(), ComponentBuilder.FormatRetention.NONE)
+ .color(plugin.isEnabled() ? net.md_5.bungee.api.ChatColor.GREEN : net.md_5.bungee.api.ChatColor.RED)
+ .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, this.getHover(description)));
+
+ if (versionCommand) {
+ builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/version " + description.getName()));
+ }
+
+ if (i != plugins.size() - 1) {
+ // add separator
+ builder.append(", ", ComponentBuilder.FormatRetention.NONE);
+ }
+ }
+
+ return builder.create();
+ }
+
+ /**
+ * Formats the hover component for a plugin.
+ *
+ * @param description The plugin's description file.
+ * @return The resulting components.
+ */
+ private BaseComponent[] getHover(PluginDescriptionFile description) {
+ net.md_5.bungee.api.ChatColor mainColor = net.md_5.bungee.api.ChatColor.YELLOW;
+ net.md_5.bungee.api.ChatColor secondaryColor = net.md_5.bungee.api.ChatColor.WHITE;
+
+ ComponentBuilder builder = new ComponentBuilder("Name: ").color(mainColor)
+ .append(description.getName()).color(secondaryColor)
+ .append("\n")
+ .append("Version: ").color(mainColor)
+ .append(description.getVersion()).color(secondaryColor);
+
+ if (description.getDescription() != null) {
+ builder
+ .append("\n")
+ .append("Description: ").color(mainColor)
+ .append(description.getDescription()).color(secondaryColor);
+ }
+
+ if (description.getWebsite() != null) {
+ builder
+ .append("\n")
+ .append("Website: ").color(mainColor)
+ .append(description.getWebsite()).color(secondaryColor);
+ }
+
+ java.util.List<String> authors = description.getAuthors();
+ if (authors != null && !authors.isEmpty()) {
+ builder
+ .append("\n")
+ .append("Authors: ").color(mainColor);
+
+ for (int i = 0; i < authors.size(); i++) {
+ String author = authors.get(i);
+
+ builder.append(author).color(secondaryColor);
+
+ if (i != authors.size() - 1) {
+ // add separator if it's not the last author
+ builder.append(", ").color(net.md_5.bungee.api.ChatColor.GRAY);
+ }
+ }
+ }
+
+ return builder.create();
+ }
+ // PandaSpigot end
+
private String getPluginList() {
StringBuilder pluginList = new StringBuilder();
Plugin[] plugins = Bukkit.getPluginManager().getPlugins();