Only show commands that the player can use in /help

This commit is contained in:
Melledy
2024-05-20 05:31:38 -07:00
parent 71cf92e139
commit 3049a18f88
2 changed files with 7 additions and 2 deletions

View File

@@ -86,7 +86,7 @@ public class CommandManager {
* @param command * @param command
* @return true if the sender has permission to use this command * @return true if the sender has permission to use this command
*/ */
private boolean checkPermission(Player sender, Command command) { public boolean checkPermission(Player sender, Command command) {
if (sender == null || command.permission().isEmpty()) { if (sender == null || command.permission().isEmpty()) {
return true; return true;
} }

View File

@@ -12,12 +12,17 @@ public class HelpCommand implements CommandHandler {
public void execute(CommandArgs args) { public void execute(CommandArgs args) {
args.sendMessage("Displaying list of commands:"); args.sendMessage("Displaying list of commands:");
// Sort command names
var labels = LunarCore.getCommandManager().getLabels().keySet().stream().sorted().toList(); var labels = LunarCore.getCommandManager().getLabels().keySet().stream().sorted().toList();
for (var label : labels) { for (var label : labels) {
// Get command
Command command = LunarCore.getCommandManager().getLabels().get(label).getClass().getAnnotation(Command.class); Command command = LunarCore.getCommandManager().getLabels().get(label).getClass().getAnnotation(Command.class);
if (command == null) continue; if (command == null) continue;
args.sendMessage(command.desc()); // Only send command description if the sender has permission to use the command
if (LunarCore.getCommandManager().checkPermission(args.getSender(), command)) {
args.sendMessage(command.desc());
}
} }
} }