Search in sources :

Example 1 with CommandArgumentDescription

use of fr.xephi.authme.command.CommandArgumentDescription in project AuthMeReloaded by AuthMe.

the class HelpProvider method addArgumentsInfo.

/**
     * Adds help info about the given command's arguments into the provided list.
     *
     * @param command the command to generate arguments info for
     * @param lines the output collection to add the info to
     */
private void addArgumentsInfo(CommandDescription command, List<String> lines) {
    if (command.getArguments().isEmpty()) {
        return;
    }
    lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.ARGUMENTS) + ":");
    StringBuilder argString = new StringBuilder();
    String optionalText = " (" + helpMessagesService.getMessage(HelpMessage.OPTIONAL) + ")";
    for (CommandArgumentDescription argument : command.getArguments()) {
        argString.setLength(0);
        argString.append(" ").append(ChatColor.YELLOW).append(ChatColor.ITALIC).append(argument.getName()).append(": ").append(ChatColor.WHITE).append(argument.getDescription());
        if (argument.isOptional()) {
            argString.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(optionalText);
        }
        lines.add(argString.toString());
    }
}
Also used : CommandArgumentDescription(fr.xephi.authme.command.CommandArgumentDescription)

Example 2 with CommandArgumentDescription

use of fr.xephi.authme.command.CommandArgumentDescription in project AuthMeReloaded by AuthMe.

the class HelpMessagesService method buildLocalizedDescription.

/**
     * Creates a copy of the supplied command description with localized messages where present.
     *
     * @param command the command to build a localized version of
     * @return the localized description
     */
public CommandDescription buildLocalizedDescription(CommandDescription command) {
    final String path = getCommandPath(command);
    if (!messageFileHandler.hasSection(path)) {
        // Messages file does not have a section for this command - return the provided command
        return command;
    }
    CommandDescription.CommandBuilder builder = CommandDescription.builder().description(getText(path + DESCRIPTION_SUFFIX, command::getDescription)).detailedDescription(getText(path + DETAILED_DESCRIPTION_SUFFIX, command::getDetailedDescription)).executableCommand(command.getExecutableCommand()).parent(command.getParent()).labels(command.getLabels()).permission(command.getPermission());
    int i = 1;
    for (CommandArgumentDescription argument : command.getArguments()) {
        String argPath = path + ".arg" + i;
        String label = getText(argPath + ".label", argument::getName);
        String description = getText(argPath + ".description", argument::getDescription);
        builder.withArgument(label, description, argument.isOptional());
        ++i;
    }
    CommandDescription localCommand = builder.build();
    localCommand.getChildren().addAll(command.getChildren());
    return localCommand;
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) CommandArgumentDescription(fr.xephi.authme.command.CommandArgumentDescription)

Example 3 with CommandArgumentDescription

use of fr.xephi.authme.command.CommandArgumentDescription in project AuthMeReloaded by AuthMe.

the class CommandPageCreater method formatArguments.

private static String formatArguments(Iterable<CommandArgumentDescription> arguments) {
    StringBuilder result = new StringBuilder();
    for (CommandArgumentDescription argument : arguments) {
        String argumentName = argument.isOptional() ? "[" + argument.getName() + "]" : "&lt;" + argument.getName() + ">";
        result.append(" ").append(argumentName);
    }
    return result.toString();
}
Also used : CommandArgumentDescription(fr.xephi.authme.command.CommandArgumentDescription)

Aggregations

CommandArgumentDescription (fr.xephi.authme.command.CommandArgumentDescription)3 CommandDescription (fr.xephi.authme.command.CommandDescription)1