Search in sources :

Example 11 with CommandDescription

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

the class HelpProviderTest method shouldShowCommandSyntaxWithCorrectLabels.

/**
     * Since command parts may be mapped to a command description with labels that don't completely correspond to it,
     * (e.g. suggest "register command" for /authme ragister), we need to check the labels and construct a correct list
     */
@Test
public void shouldShowCommandSyntaxWithCorrectLabels() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme", "register");
    FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "ragister"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_COMMAND);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(2));
    assertThat(lines.get(0), containsString("Header"));
    assertThat(lines.get(1), containsString("Command: /authme register <password> <confirmation>"));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with CommandDescription

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

the class HelpProviderTest method shouldShowSpecifyIfArgumentIsOptional.

@Test
public void shouldShowSpecifyIfArgumentIsOptional() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "email");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("email"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_ARGUMENTS);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(3));
    assertThat(lines.get(2), containsString("player: 'player' argument description (Optional)"));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with CommandDescription

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

the class HelpProviderTest method shouldNotShowAnythingIfCommandHasNoArguments.

/** Verifies that the "Arguments:" line is not shown if the command has no arguments. */
@Test
public void shouldNotShowAnythingIfCommandHasNoArguments() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_ARGUMENTS);
    // then
    List<String> lines = getLines(sender);
    // only has the help banner
    assertThat(lines, hasSize(1));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with CommandDescription

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

the class HelpProvider method buildHelpOutput.

/**
     * Builds the help messages based on the provided arguments.
     *
     * @param sender the sender to evaluate permissions with
     * @param result the command result to create help for
     * @param options output options
     * @return the generated help messages
     */
private List<String> buildHelpOutput(CommandSender sender, FoundCommandResult result, int options) {
    if (result.getCommandDescription() == null) {
        return singletonList(ChatColor.DARK_RED + "Failed to retrieve any help information!");
    }
    List<String> lines = new ArrayList<>();
    options = filterDisabledSections(options);
    if (options == 0) {
        // Return directly if no options are enabled so we don't include the help header
        return lines;
    }
    String header = helpMessagesService.getMessage(HelpMessage.HEADER);
    if (!header.isEmpty()) {
        lines.add(ChatColor.GOLD + header);
    }
    CommandDescription command = helpMessagesService.buildLocalizedDescription(result.getCommandDescription());
    List<String> correctLabels = ImmutableList.copyOf(filterCorrectLabels(command, result.getLabels()));
    if (hasFlag(SHOW_COMMAND, options)) {
        lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.COMMAND) + ": " + CommandUtils.buildSyntax(command, correctLabels));
    }
    if (hasFlag(SHOW_DESCRIPTION, options)) {
        lines.add(ChatColor.GOLD + helpMessagesService.getMessage(SHORT_DESCRIPTION) + ": " + ChatColor.WHITE + command.getDescription());
    }
    if (hasFlag(SHOW_LONG_DESCRIPTION, options)) {
        lines.add(ChatColor.GOLD + helpMessagesService.getMessage(DETAILED_DESCRIPTION) + ":");
        lines.add(ChatColor.WHITE + " " + command.getDetailedDescription());
    }
    if (hasFlag(SHOW_ARGUMENTS, options)) {
        addArgumentsInfo(command, lines);
    }
    if (hasFlag(SHOW_PERMISSIONS, options) && sender != null) {
        addPermissionsInfo(command, sender, lines);
    }
    if (hasFlag(SHOW_ALTERNATIVES, options)) {
        addAlternativesInfo(command, correctLabels, lines);
    }
    if (hasFlag(SHOW_CHILDREN, options)) {
        addChildrenInfo(command, correctLabels, lines);
    }
    return lines;
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) ArrayList(java.util.ArrayList)

Example 15 with CommandDescription

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

the class HelpProvider method addChildrenInfo.

/**
     * Adds help info about the given command's child command into the provided list.
     *
     * @param command the command for which to generate info about its child commands
     * @param correctLabels the labels used to access the given command (sanitized)
     * @param lines the output collection to add the info to
     */
private void addChildrenInfo(CommandDescription command, List<String> correctLabels, List<String> lines) {
    if (command.getChildren().isEmpty()) {
        return;
    }
    lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.CHILDREN) + ":");
    String parentCommandPath = String.join(" ", correctLabels);
    for (CommandDescription child : command.getChildren()) {
        lines.add(" /" + parentCommandPath + " " + child.getLabels().get(0) + ChatColor.GRAY + ChatColor.ITALIC + ": " + helpMessagesService.getDescription(child));
    }
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription)

Aggregations

CommandDescription (fr.xephi.authme.command.CommandDescription)38 Test (org.junit.Test)30 Matchers.containsString (org.hamcrest.Matchers.containsString)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)20 CommandInitializer (fr.xephi.authme.command.CommandInitializer)4 CommandSender (org.bukkit.command.CommandSender)3 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 TestHelper (fr.xephi.authme.TestHelper)1 CommandArgumentDescription (fr.xephi.authme.command.CommandArgumentDescription)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 MemorySection (org.bukkit.configuration.MemorySection)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1