Search in sources :

Example 1 with CommandUsageBox

use of com.sk89q.worldedit.util.formatting.component.CommandUsageBox in project FastAsyncWorldEdit by IntellectualSites.

the class PrintCommandHelp method help.

public static void help(List<String> commandPath, int page, boolean listSubCommands, CommandManager manager, Actor actor, String helpRootCommand) throws InvalidComponentException {
    if (commandPath.isEmpty()) {
        printCommands(page, manager.getAllCommands(), actor, ImmutableList.of(), helpRootCommand);
        return;
    }
    List<Command> visited = new ArrayList<>();
    Command currentCommand = detectCommand(manager, commandPath.get(0));
    if (currentCommand == null) {
        actor.print(Caption.of("worldedit.help.command-not-found", TextComponent.of(commandPath.get(0))));
        return;
    }
    visited.add(currentCommand);
    // Drill down to the command
    for (int i = 1; i < commandPath.size(); i++) {
        String subCommand = commandPath.get(i);
        Map<String, Command> subCommands = getSubCommands(currentCommand);
        if (subCommands.isEmpty()) {
            actor.print(Caption.of("worldedit.help.no-subcommands", TextComponent.of(toCommandString(visited)), TextComponent.of(subCommand)));
            // full help for single command
            CommandUsageBox box = new CommandUsageBox(visited, visited.stream().map(Command::getName).collect(Collectors.joining(" ")), helpRootCommand);
            actor.print(box.create());
            return;
        }
        if (subCommands.containsKey(subCommand)) {
            currentCommand = subCommands.get(subCommand);
            visited.add(currentCommand);
        } else {
            actor.print(Caption.of("worldedit.help.subcommand-not-found", TextComponent.of(subCommand), TextComponent.of(toCommandString(visited))));
            // list subcommands for currentCommand
            printCommands(page, getSubCommands(Iterables.getLast(visited)).values().stream(), actor, visited, helpRootCommand);
            return;
        }
    }
    Map<String, Command> subCommands = getSubCommands(currentCommand);
    if (subCommands.isEmpty() || !listSubCommands) {
        // Create the message
        CommandUsageBox box = new CommandUsageBox(visited, toCommandString(visited), helpRootCommand);
        actor.print(box.create());
    } else {
        printCommands(page, subCommands.values().stream(), actor, visited, helpRootCommand);
    }
}
Also used : CommandUsageBox(com.sk89q.worldedit.util.formatting.component.CommandUsageBox) Command(org.enginehub.piston.Command) ArrayList(java.util.ArrayList)

Aggregations

CommandUsageBox (com.sk89q.worldedit.util.formatting.component.CommandUsageBox)1 ArrayList (java.util.ArrayList)1 Command (org.enginehub.piston.Command)1