mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Only show commands that the player can use in /help
This commit is contained in:
@@ -86,7 +86,7 @@ public class CommandManager {
|
||||
* @param 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()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,13 +12,18 @@ public class HelpCommand implements CommandHandler {
|
||||
public void execute(CommandArgs args) {
|
||||
args.sendMessage("Displaying list of commands:");
|
||||
|
||||
// Sort command names
|
||||
var labels = LunarCore.getCommandManager().getLabels().keySet().stream().sorted().toList();
|
||||
for (var label : labels) {
|
||||
// Get command
|
||||
Command command = LunarCore.getCommandManager().getLabels().get(label).getClass().getAnnotation(Command.class);
|
||||
if (command == null) continue;
|
||||
|
||||
// Only send command description if the sender has permission to use the command
|
||||
if (LunarCore.getCommandManager().checkPermission(args.getSender(), command)) {
|
||||
args.sendMessage(command.desc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user