Package com.sk89q.minecraft.util.commands

Examples of com.sk89q.minecraft.util.commands.Command


     * @param object the object contain the methods
     * @throws ParametricException thrown if the commands cannot be registered
     */
    public void registerMethodsAsCommands(Dispatcher dispatcher, Object object) throws ParametricException {
        for (Method method : object.getClass().getDeclaredMethods()) {
            Command definition = method.getAnnotation(Command.class);
            if (definition != null) {
                CommandCallable callable = build(object, method, definition);
                dispatcher.registerCommand(callable, definition.aliases());
            }
        }
    }
View Full Code Here


            for (Method method : cls.getMethods()) {
                if (!method.isAnnotationPresent(Command.class)) {
                    continue;
                }

                Command cmd = method.getAnnotation(Command.class);

                stream.println("|-");
                stream.print("| " + prefix + cmd.aliases()[0]);
                stream.print(" || ");

                if (method.isAnnotationPresent(CommandPermissions.class)) {
                    CommandPermissions perms =
                            method.getAnnotation(CommandPermissions.class);

                    String[] permKeys = perms.value();
                    for (int i = 0; i < permKeys.length; ++i) {
                        if (i > 0) {
                            stream.print(", ");
                        }
                        stream.print(permKeys[i]);
                    }
                }

                stream.print(" || ");

                boolean firstAlias = true;
                if (cmd.aliases().length != 0) {
                    for (String alias : cmd.aliases()) {
                        if (!firstAlias) stream.print("<br />");
                        stream.print(prefix + alias);
                        firstAlias = false;
                    }
                }

                stream.print(" || ");

                if (cmd.flags() != null && !cmd.flags().equals("")) {
                    stream.print(cmd.flags());
                }

                stream.print(" || ");

                if (cmd.desc() != null && !cmd.desc().equals("")) {
                    stream.print(cmd.desc());
                }

                stream.println();

                if (method.isAnnotationPresent(NestedCommand.class)) {
                    NestedCommand nested =
                            method.getAnnotation(NestedCommand.class);

                    Class<?>[] nestedClasses = nested.value();
                    writePermissionsWikiTable(stream,
                            Arrays.asList(nestedClasses),
                            prefix + cmd.aliases()[0] + " ");
                }
            }
        }
    }
View Full Code Here

    @Override
    public void preInvoke(Object object, Method method,
            ParameterData[] parameters, Object[] args, CommandContext context)
            throws ParameterException {
        Command annotation = method.getAnnotation(Command.class);
       
        if (annotation != null) {
            if (context.argsLength() < annotation.min()) {
                throw new MissingParameterException();
            }
   
            if (annotation.max() != -1 && context.argsLength() > annotation.max()) {
                throw new UnconsumedParameterException(
                        context.getRemainingString(annotation.max()));
            }
        }
    }
View Full Code Here

    }

    @Override
    public void updateDescription(Object object, Method method,
            ParameterData[] parameters, SimpleDescription description) {
        Command annotation = method.getAnnotation(Command.class);
       
        // Handle the case for old commands where no usage is set and all of its
        // parameters are provider bindings, so its usage information would
        // be blank and would imply that there were no accepted parameters
        if (annotation != null && annotation.usage().isEmpty()
                && (annotation.min() > 0 || annotation.max() > 0)) {
            boolean hasUserParameters = false;
           
            for (ParameterData parameter : parameters) {
                if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) {
                    hasUserParameters = true;
View Full Code Here

TOP

Related Classes of com.sk89q.minecraft.util.commands.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.