Search in sources :

Example 16 with CommandDescription

use of fr.xephi.authme.command.CommandDescription 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 17 with CommandDescription

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

the class HelpCommandTest method shouldShowChildrenOfBaseCommand.

@Test
public void shouldShowChildrenOfBaseCommand() {
    List<String> arguments = singletonList("authme");
    CommandSender sender = mock(CommandSender.class);
    CommandDescription commandDescription = mock(CommandDescription.class);
    given(commandDescription.getLabelCount()).willReturn(1);
    FoundCommandResult foundCommandResult = new FoundCommandResult(commandDescription, singletonList("authme"), Collections.emptyList(), 0.0, SUCCESS);
    given(commandMapper.mapPartsToCommand(sender, arguments)).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, arguments);
    // then
    verify(sender, never()).sendMessage(anyString());
    verify(helpProvider).outputHelp(sender, foundCommandResult, SHOW_DESCRIPTION | SHOW_COMMAND | SHOW_CHILDREN | SHOW_ALTERNATIVES);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 18 with CommandDescription

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

the class HelpCommandTest method newCommandDescription.

private static CommandDescription newCommandDescription(String... labels) {
    CommandDescription parent = null;
    // iterate through the labels backwards so we can set the parent
    for (String label : labels) {
        CommandDescription description = mock(CommandDescription.class);
        given(description.getParent()).willReturn(parent);
        given(description.getLabels()).willReturn(singletonList(label));
        parent = description;
    }
    return parent;
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 19 with CommandDescription

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

the class HelpCommandTest method shouldShowDetailedHelpForChildCommand.

@Test
public void shouldShowDetailedHelpForChildCommand() {
    List<String> arguments = asList("authme", "getpos");
    CommandSender sender = mock(CommandSender.class);
    CommandDescription commandDescription = mock(CommandDescription.class);
    given(commandDescription.getLabelCount()).willReturn(2);
    FoundCommandResult foundCommandResult = new FoundCommandResult(commandDescription, asList("authme", "getpos"), Collections.emptyList(), 0.0, INCORRECT_ARGUMENTS);
    given(commandMapper.mapPartsToCommand(sender, arguments)).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, arguments);
    // then
    verify(sender, never()).sendMessage(anyString());
    verify(helpProvider).outputHelp(sender, foundCommandResult, HelpProvider.ALL_OPTIONS);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 20 with CommandDescription

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

the class CommandPageCreater method executeDefault.

@Override
public void executeDefault() {
    CommandInitializer commandInitializer = new CommandInitializer();
    final Collection<CommandDescription> baseCommands = commandInitializer.getCommands();
    NestedTagValue commandTags = new NestedTagValue();
    addCommandsInfo(commandTags, baseCommands);
    FileIoUtils.generateFileFromTemplate(ToolsConstants.TOOLS_SOURCE_ROOT + "docs/commands/commands.tpl.md", OUTPUT_FILE, TagValueHolder.create().put("commands", commandTags));
    System.out.println("Wrote to '" + OUTPUT_FILE + "' with " + baseCommands.size() + " base commands.");
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) CommandInitializer(fr.xephi.authme.command.CommandInitializer) NestedTagValue(tools.utils.TagValue.NestedTagValue)

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