use of org.cubeengine.butler.Dispatcher in project core by CubeEngine.
the class CubeCommandManager method injectCommands.
public void injectCommands(Injector injector, Object module, List<Field> fields) {
for (Field field : fields) {
Class<? extends ContainerCommand> parent = field.getAnnotation(ModuleCommand.class).value();
Dispatcher dispatcher = parent == ContainerCommand.class ? this : getDispatcher(parent);
Object command = injector.getInstance(field.getType());
boolean isCommand = CommandBase.class.isAssignableFrom(command.getClass());
if (isCommand) {
dispatcher.addCommand(((CommandBase) command));
if (command instanceof Dispatcher) {
this.injectedDispatchers.put(command.getClass(), ((Dispatcher) command));
}
} else {
addCommands(dispatcher, module, command);
}
try {
field.setAccessible(true);
field.set(module, command);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
Aggregations