Search in sources :

Example 1 with InvokableMethod

use of org.cubeengine.butler.parametric.InvokableMethod in project core by CubeEngine.

the class CubeCommandManager method addCommands.

/**
 * Creates {@link org.cubeengine.butler.parametric.BasicParametricCommand} for all methods annotated as a command
 * in the given commandHolder and add them to the given dispatcher
 *
 * @param dispatcher    the dispatcher to add the commands to
 * @param owner        the module owning the commands
 * @param commandHolder the command holder containing the command-methods
 */
@SuppressWarnings("unchecked")
@Override
public void addCommands(Dispatcher dispatcher, Object owner, Object commandHolder) {
    Set<CommandBase> cmds = this.commands.get(owner);
    if (cmds == null) {
        cmds = new HashSet<>();
    }
    this.commands.put(owner, cmds);
    dispatcher = new OwnedDispatcher(dispatcher, owner);
    for (Method method : ParametricBuilder.getMethods(commandHolder.getClass())) {
        CommandBuilder<InvokableMethod> builder = getProviders().getBuilder(InvokableMethod.class);
        CommandBase cmd = builder.buildCommand(dispatcher, new InvokableMethod(method, commandHolder));
        if (cmd != null) {
            dispatcher.addCommand(cmd);
            cmds.add(cmd);
        }
    }
}
Also used : CommandBase(org.cubeengine.butler.CommandBase) Method(java.lang.reflect.Method) InvokableMethod(org.cubeengine.butler.parametric.InvokableMethod) InvokableMethod(org.cubeengine.butler.parametric.InvokableMethod)

Aggregations

Method (java.lang.reflect.Method)1 CommandBase (org.cubeengine.butler.CommandBase)1 InvokableMethod (org.cubeengine.butler.parametric.InvokableMethod)1