Skip to content

Commit 109aad0

Browse files
committed
Forgot to update the command dispatcher to support aliases...
1 parent 0158739 commit 109aad0

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/main/java/org/mangorage/mangobotcore/internal/command/CommandDispatcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
public final class CommandDispatcher<C, R> implements ICommandDispatcher<C, R> {
1414
private final Map<String, AbstractCommand<C, R>> roots = new HashMap<>();
15+
private final Map<String, AbstractCommand<C, R>> aliasRoots = new HashMap<>();
1516
private final R defaultInvalid;
1617

1718
public CommandDispatcher(R defaultInvalid) {
@@ -24,11 +25,14 @@ public void register(AbstractCommand<C, R> commandNode) {
2425
commandNode.getName(),
2526
commandNode
2627
);
28+
commandNode.aliases().forEach(alias -> {
29+
aliasRoots.put(alias, commandNode);
30+
});
2731
}
2832

2933
@Override
3034
public AbstractCommand<C, R> getCommand(String name) {
31-
return roots.get(name);
35+
return roots.getOrDefault(name, aliasRoots.get(name));
3236
}
3337

3438
@Override
@@ -42,7 +46,7 @@ public R execute(String input, C context, CommandParseResult commandParseResult)
4246
if (split.length == 0)
4347
return defaultInvalid;
4448

45-
AbstractCommand<C, R> root = roots.get(split[0]);
49+
AbstractCommand<C, R> root = getCommand(split[0]);
4650
if (root == null)
4751
return defaultInvalid;
4852

0 commit comments

Comments
 (0)