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
|
* @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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user