added ability to define aliases in the code

This commit is contained in:
Sheldan
2020-04-04 17:29:49 +02:00
parent 20b282584a
commit a957c66905
4 changed files with 18 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ public class CommandManager implements CommandRegistry {
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
CommandConfiguration commandConfiguration = o.getConfiguration();
if(!commandConfiguration.getName().equalsIgnoreCase(name)) {
if(!commandNameMatches(name, commandConfiguration)) {
return false;
}
boolean parameterFit;
@@ -49,6 +49,18 @@ public class CommandManager implements CommandRegistry {
throw new CommandNotFound("Command not found.");
}
private boolean commandNameMatches(String name, CommandConfiguration commandConfiguration) {
boolean commandNameMatches = commandConfiguration.getName().equalsIgnoreCase(name);
if(commandNameMatches) {
return true;
}
boolean aliasesMatch = false;
if(commandConfiguration.getAliases() != null) {
aliasesMatch = commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
}
return aliasesMatch;
}
public Command findCommand(String name) {
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
CommandConfiguration commandConfiguration = o.getConfiguration();