Skip to content

Commit

Permalink
Fix help entries to include all children commands of the help's parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Apr 22, 2022
1 parent 2b34462 commit 8fe6d51
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions common/src/main/java/revxrsal/commands/core/BaseCommandHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ public Resolver(BaseCommandHandler handler) {
@Override public CommandHelp<?> resolve(@NotNull ContextResolverContext context) {
if (handler.getHelpWriter() == null)
throw new IllegalArgumentException("No help writer is registered!");
ExecutableCommand command = context.command();
ExecutableCommand helpCommand = context.command();
CommandHelpWriter<?> writer = handler.getHelpWriter();
BaseCommandHelp<Object> entries = new BaseCommandHelp<>();
CommandCategory parent = command.getParent();
if (parent != null) {
parent.getCommands().values().forEach(c -> {
if (c != command) entries.add(writer.generate(c, context.actor()));
});
} else {
handler.executables.values().forEach(c -> {
if (c != command) entries.add(writer.generate(c, context.actor()));
});
CommandCategory parent = helpCommand.getParent();
CommandPath parentPath = parent == null ? null : parent.getPath();
for (CommandExecutable c : handler.executables.values()) {
if (parentPath == null || parentPath.isParentOf(c.getPath())) {
if (c != helpCommand)
entries.add(writer.generate(c, context.actor()));
}
}
return entries;
}
Expand Down

0 comments on commit 8fe6d51

Please sign in to comment.