Skip to content

Commit 8e13028

Browse files
committed
Fixed debug annotation not working on registering commands/completers
1 parent e88fcaf commit 8e13028

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/main/java/dev/despical/commandframework/internal/CommandRegistry.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,27 @@ public CommandRegistry() {
8888

8989
public void registerCommands(@NotNull Object instance) {
9090
var framework = CommandFramework.getInstance();
91-
boolean notDebug = !framework.options().isEnabled(FrameworkOption.DEBUG);
91+
boolean debugEnabled = framework.options().isEnabled(FrameworkOption.DEBUG);
9292

93-
for (Method method : instance.getClass().getMethods()) {
94-
if (notDebug && method.isAnnotationPresent(Debug.class)) continue;
93+
Class<?> clazz = instance.getClass();
94+
95+
if (!debugEnabled && clazz.isAnnotationPresent(Debug.class)) {
96+
return;
97+
}
98+
99+
for (Method method : clazz.getMethods()) {
100+
if (!debugEnabled && method.isAnnotationPresent(Debug.class)) {
101+
continue;
102+
}
95103

96104
Command command = method.getAnnotation(Command.class);
97105

98106
if (command != null) {
99107
this.registerCommand(command, method, instance);
100-
} else if (method.isAnnotationPresent(Completer.class)) {
108+
continue;
109+
}
110+
111+
if (method.isAnnotationPresent(Completer.class)) {
101112
this.registerCompleter(instance, method);
102113
}
103114
}
@@ -106,7 +117,9 @@ public void registerCommands(@NotNull Object instance) {
106117
}
107118

108119
public void registerAllInPackage(@NotNull String packageName) {
109-
Plugin plugin = CommandFramework.getInstance().getPlugin();
120+
var framework = CommandFramework.getInstance();
121+
boolean debugEnabled = framework.options().isEnabled(FrameworkOption.DEBUG);
122+
Plugin plugin = framework.getPlugin();
110123

111124
try {
112125
ClassPath cp = ClassPath.from(plugin.getClass().getClassLoader());
@@ -118,19 +131,26 @@ public void registerAllInPackage(@NotNull String packageName) {
118131
continue;
119132
}
120133

134+
if (!debugEnabled && clazz.isAnnotationPresent(Debug.class)) {
135+
continue;
136+
}
137+
121138
try {
122139
Object instance = clazz.getDeclaredConstructor().newInstance();
123140

124141
for (Method method : clazz.getDeclaredMethods()) {
142+
if (!debugEnabled && method.isAnnotationPresent(Debug.class)) {
143+
continue;
144+
}
145+
125146
Command command = method.getAnnotation(Command.class);
126147

127148
if (command != null) {
128149
registerCommand(command, method, instance);
150+
continue;
129151
}
130152

131-
Completer completer = method.getAnnotation(Completer.class);
132-
133-
if (completer != null) {
153+
if (method.isAnnotationPresent(Completer.class)) {
134154
registerCompleter(instance, method);
135155
}
136156
}
@@ -143,6 +163,7 @@ public void registerAllInPackage(@NotNull String packageName) {
143163
}
144164
}
145165

166+
146167
public void registerCommand(Command command, Method method, Object instance) {
147168
innerRegister(command.name(), command, method, instance);
148169

0 commit comments

Comments
 (0)