Search in sources :

Example 1 with SimpleCommand

use of cn.nukkit.command.simple.SimpleCommand in project Nukkit by Nukkit.

the class SimpleCommandMap method registerSimpleCommands.

@Override
public void registerSimpleCommands(Object object) {
    for (Method method : object.getClass().getDeclaredMethods()) {
        cn.nukkit.command.simple.Command def = method.getAnnotation(cn.nukkit.command.simple.Command.class);
        if (def != null) {
            SimpleCommand sc = new SimpleCommand(object, method, def.name(), def.description(), def.usageMessage(), def.aliases());
            Arguments args = method.getAnnotation(Arguments.class);
            if (args != null) {
                sc.setMaxArgs(args.max());
                sc.setMinArgs(args.min());
            }
            CommandPermission perm = method.getAnnotation(CommandPermission.class);
            if (perm != null) {
                sc.setPermission(perm.value());
            }
            if (method.isAnnotationPresent(ForbidConsole.class)) {
                sc.setForbidConsole(true);
            }
            this.register(def.name(), sc);
        }
    }
}
Also used : SimpleCommand(cn.nukkit.command.simple.SimpleCommand) Arguments(cn.nukkit.command.simple.Arguments) Method(java.lang.reflect.Method) CommandPermission(cn.nukkit.command.simple.CommandPermission)

Aggregations

Arguments (cn.nukkit.command.simple.Arguments)1 CommandPermission (cn.nukkit.command.simple.CommandPermission)1 SimpleCommand (cn.nukkit.command.simple.SimpleCommand)1 Method (java.lang.reflect.Method)1