Package com.sk89q.worldedit.util.command

Examples of com.sk89q.worldedit.util.command.CommandMapping


        this.dispatcher = dispatcher;
    }

    @Override
    public String getShortText(Command command) {
        CommandMapping mapping = dispatcher.get(command.getName());
        if (mapping != null) {
            return mapping.getDescription().getShortDescription();
        } else {
            logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'");
            return "Help text not available";
        }
    }
View Full Code Here


        }
    }

    @Override
    public String getFullText(Command command) {
        CommandMapping mapping = dispatcher.get(command.getName());
        if (mapping != null) {
            Description description = mapping.getDescription();
            return "Usage: " + description.getUsage() + (description.getHelp() != null ? "\n" + description.getHelp() : "");
        } else {
            logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'");
            return "Help text not available";
        }
View Full Code Here

        }
    }

    @Override
    public boolean testPermission(CommandSender sender, Command command) {
        CommandMapping mapping = dispatcher.get(command.getName());
        if (mapping != null) {
            CommandLocals locals = new CommandLocals();
            locals.put(Actor.class, plugin.wrapCommandSender(sender));
            return mapping.getCallable().testPermission(locals);
        } else {
            logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'");
            return false;
        }
    }
View Full Code Here

    public void help(Actor actor, CommandContext args) throws WorldEditException {
        help(args, we, actor);
    }

    private static CommandMapping detectCommand(Dispatcher dispatcher, String command, boolean isRootLevel) {
        CommandMapping mapping;

        // First try the command as entered
        mapping = dispatcher.get(command);
        if (mapping != null) {
            return mapping;
View Full Code Here

                // Chop off the beginning / if we're are the root level
                if (isRootLevel && command.length() > 1 && command.charAt(0) == '/') {
                    command = command.substring(1);
                }

                CommandMapping mapping = detectCommand((Dispatcher) callable, command, isRootLevel);
                if (mapping != null) {
                    callable = mapping.getCallable();
                } else {
                    if (isRootLevel) {
                        actor.printError(String.format("The command '%s' could not be found.", args.getString(i)));
                        return;
                    } else {
                        actor.printError(String.format("The sub-command '%s' under '%s' could not be found.",
                                command, Joiner.on(" ").join(visited)));
                        return;
                    }
                }

                visited.add(args.getString(i));
                isRootLevel = false;
            } else {
                actor.printError(String.format("'%s' has no sub-commands. (Maybe '%s' is for a parameter?)",
                        Joiner.on(" ").join(visited), command));
                return;
            }
        }

        // Create the message
        if (callable instanceof Dispatcher) {
            Dispatcher dispatcher = (Dispatcher) callable;

            // Get a list of aliases
            List<CommandMapping> aliases = new ArrayList<CommandMapping>(dispatcher.getCommands());
            Collections.sort(aliases, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN));

            // Calculate pagination
            int offset = perPage * page;
            int pageTotal = (int) Math.ceil(aliases.size() / (double) perPage);

            // Box
            CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal));
            StyledFragment contents = box.getContents();
            StyledFragment tip = contents.createFragment(Style.GRAY);

            if (offset >= aliases.size()) {
                tip.createFragment(Style.RED).append(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).newLine();
            } else {
                List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size()));

                tip.append("Type ");
                tip.append(new Code().append("//help ").append("<command> [<page>]"));
                tip.append(" for more information.").newLine();

                // Add each command
                for (CommandMapping mapping : list) {
                    StringBuilder builder = new StringBuilder();
                    if (isRootLevel) {
                        builder.append("/");
                    }
                    if (!visited.isEmpty()) {
                        builder.append(Joiner.on(" ").join(visited));
                        builder.append(" ");
                    }
                    builder.append(mapping.getPrimaryAlias());
                    box.appendCommand(builder.toString(), mapping.getDescription().getShortDescription());
                }
            }

            actor.printRaw(ColorCodeBuilder.asColorCodes(box));
        } else {
View Full Code Here

TOP

Related Classes of com.sk89q.worldedit.util.command.CommandMapping

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.