Skip to content

Commit cdb2637

Browse files
committed
Updated: Make commands & plugins in help command clickable
For plugins (just /help), it'll actually run the /help <name> command For plugin commands (/help <name>), clicking will suggest the command
1 parent 0f704aa commit cdb2637

File tree

1 file changed

+24
-2
lines changed
  • modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands

1 file changed

+24
-2
lines changed

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdHelp.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import org.royaldev.royalcommands.RUtils;
1616
import org.royaldev.royalcommands.RoyalCommands;
1717

18+
import net.md_5.bungee.api.chat.ClickEvent;
19+
import net.md_5.bungee.api.chat.HoverEvent;
20+
import net.md_5.bungee.api.chat.TextComponent;
21+
import net.md_5.bungee.api.chat.hover.content.Text;
22+
1823
import java.util.List;
1924
import java.util.Map;
2025
import java.util.Map.Entry;
@@ -82,7 +87,18 @@ private void displayPluginHelp(CommandSender cs, String pluginName, String page)
8287
cs.sendMessage(MessageColor.POSITIVE + "Help for " + MessageColor.NEUTRAL + p.getName() + MessageColor.POSITIVE + " (Page " + MessageColor.NEUTRAL + pageNumber + MessageColor.POSITIVE + "/" + MessageColor.NEUTRAL + numPages + MessageColor.POSITIVE + ")");
8388
for (int i = (pageNumber - 1) * Config.helpAmount; i < (pageNumber * Config.helpAmount) + Config.helpAmount && i < pCommands.size(); i++) {
8489
final PluginCommand pc = pCommands.get(i);
85-
cs.sendMessage(MessageColor.NEUTRAL + "/" + pc.getName() + MessageColor.POSITIVE + " - " + pc.getDescription());
90+
String cmdTxt = "/" + pc.getName();
91+
TextComponent tt = new TextComponent(" ");
92+
TextComponent cmd = new TextComponent(cmdTxt);
93+
cmd.setColor(MessageColor.NEUTRAL.bc());
94+
// cmd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to ")));
95+
cmd.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cmdTxt));
96+
tt.addExtra(cmd);
97+
TextComponent desc = new TextComponent(" - " + pc.getDescription());
98+
desc.setColor(MessageColor.POSITIVE.bc());
99+
// desc.setClickEvent(null);
100+
tt.addExtra(desc);
101+
cs.spigot().sendMessage(tt);
86102
}
87103
}
88104

@@ -93,7 +109,13 @@ private void displayPluginList(CommandSender cs) {
93109
final String pluginName = entry.getKey();
94110
final Plugin p = getPlugin(pluginName);
95111
if (p == null) continue;
96-
cs.sendMessage(MessageColor.NEUTRAL + p.getName());
112+
TextComponent tt = new TextComponent(" ");
113+
TextComponent pName = new TextComponent(p.getName());
114+
pName.setColor(MessageColor.NEUTRAL.bc());
115+
pName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to display help")));
116+
pName.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help " + p.getName()));
117+
tt.addExtra(pName);
118+
cs.spigot().sendMessage(tt);
97119
}
98120
}
99121

0 commit comments

Comments
 (0)