Skip to content

Commit b58bc8f

Browse files
committed
Respect both declared and inherited methods
1 parent 71d5154 commit b58bc8f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎common/src/main/java/revxrsal/commands/core/CommandParser.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void parse(@NotNull BaseCommandHandler handler, CommandCompound re
4646
Map<CommandPath, CommandExecutable> executables = registration.getExecutables();
4747
Map<CommandPath, BaseCommandCategory> categories = registration.getSubcategories();
4848
Map<CommandPath, CommandExecutable> subactions = new HashMap<>();
49-
for (Method method : container.getMethods()) {
49+
for (Method method : getAllMethods(container)) {
5050
AnnotationReader reader = new AnnotationReader(container, method);
5151
if (reader.isEmpty()) continue;
5252
List<CommandPath> paths = getCommandPath(container, method, reader);
@@ -89,6 +89,16 @@ public static void parse(@NotNull BaseCommandHandler handler, CommandCompound re
8989
});
9090
}
9191

92+
private static Set<Method> getAllMethods(Class<?> c) {
93+
Set<Method> methods = new HashSet<>();
94+
Class<?> current = c;
95+
while (current != null && current != Object.class) {
96+
addAll(methods, current.getDeclaredMethods());
97+
current = current.getSuperclass();
98+
}
99+
return methods;
100+
}
101+
92102
private static String generateUsage(@NotNull ExecutableCommand command) {
93103
StringJoiner joiner = new StringJoiner(" ");
94104
CommandHandler handler = command.getCommandHandler();

0 commit comments

Comments
 (0)