Make '/help [command]' work with aliases

This commit is contained in:
kuroppoi 2023-02-06 21:10:39 +01:00
parent dfbfe5ebb0
commit ac71f0f9c1
2 changed files with 7 additions and 3 deletions

View file

@ -107,7 +107,7 @@ public class CommandManager {
commandName = commandName.substring(1);
}
Command command = commands.getOrDefault(commandName, aliases.get(commandName));
Command command = getCommand(commandName, true);
if(command == null || !command.canExecute(executor)) {
executor.notify("Unknown command. Type '/help' for a list of commands.", SYSTEM);
@ -153,7 +153,11 @@ public class CommandManager {
}
public static Command getCommand(String name) {
return commands.get(name);
return getCommand(name, false);
}
public static Command getCommand(String name, boolean allowAlias) {
return commands.getOrDefault(name, allowAlias ? aliases.get(name) : null);
}
public static Collection<Command> getCommands() {

View file

@ -33,7 +33,7 @@ public class HelpCommand extends Command {
arg = arg.substring(1);
}
Command command = CommandManager.getCommand(arg);
Command command = CommandManager.getCommand(arg, true);
// If command does not exist (or can not be used by the executor) then notify the executor of this.
if(command == null || !command.canExecute(executor)) {