Skip to content

Commit 2f57a33

Browse files
committed
Throw exception after registering commands
1 parent 8c952c2 commit 2f57a33

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/me/despical/commandframework/CommandFramework.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,18 @@ public void registerCommands(@NotNull Object instance) {
160160

161161
subCommands.forEach((key, value) -> {
162162
final String splitName = key.name().split("\\.")[0];
163+
boolean shouldThrowException = false;
163164

164165
// This is an unsupported behaviour at least for now.
165166
// All sub-commands must have their own main command to be registered.
166167
if (commands.keySet().stream().noneMatch(cmd -> cmd.name().equals(splitName))) {
168+
shouldThrowException = true;
169+
167170
unregisterCommand(key.name());
168-
throw new IllegalStateException(String.format("You can not create sub-commands without a main command! (%s)", key.name()));
169171
}
172+
173+
if (shouldThrowException)
174+
throw new IllegalStateException(String.format("You can not create sub-commands without a main command! (%s)", key.name()));
170175
});
171176
}
172177

0 commit comments

Comments
 (0)