Search in sources :

Example 11 with FoundCommandResult

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

the class HelpCommand method executeCommand.

// Convention: arguments is not the actual invoked arguments but the command that was invoked,
// e.g. "/authme help register" would typically be arguments = [register], but here we pass [authme, register]
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    FoundCommandResult result = commandMapper.mapPartsToCommand(sender, arguments);
    FoundResultStatus resultStatus = result.getResultStatus();
    if (MISSING_BASE_COMMAND.equals(resultStatus)) {
        sender.sendMessage(ChatColor.DARK_RED + "Could not get base command");
        return;
    } else if (UNKNOWN_LABEL.equals(resultStatus)) {
        if (result.getCommandDescription() == null) {
            sender.sendMessage(ChatColor.DARK_RED + "Unknown command");
            return;
        } else {
            sender.sendMessage(ChatColor.GOLD + "Assuming " + ChatColor.WHITE + CommandUtils.constructCommandPath(result.getCommandDescription()));
        }
    }
    int mappedCommandLevel = result.getCommandDescription().getLabelCount();
    if (mappedCommandLevel == 1) {
        helpProvider.outputHelp(sender, result, SHOW_COMMAND | SHOW_DESCRIPTION | SHOW_CHILDREN | SHOW_ALTERNATIVES);
    } else {
        helpProvider.outputHelp(sender, result, ALL_OPTIONS);
    }
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) FoundResultStatus(fr.xephi.authme.command.FoundResultStatus)

Example 12 with FoundCommandResult

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

the class EmailBaseCommand method executeCommand.

@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    FoundCommandResult result = commandMapper.mapPartsToCommand(sender, Collections.singletonList("email"));
    helpProvider.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult)

Example 13 with FoundCommandResult

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

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

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

the class HelpCommandTest method shouldHandleWrongCommandWithoutSuggestion.

@Test
public void shouldHandleWrongCommandWithoutSuggestion() {
    List<String> arguments = asList("authme", "ragister", "test");
    CommandSender sender = mock(CommandSender.class);
    FoundCommandResult foundCommandResult = new FoundCommandResult(null, asList("authme", "ragister"), singletonList("test"), 0.4, UNKNOWN_LABEL);
    given(commandMapper.mapPartsToCommand(sender, arguments)).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, arguments);
    // then
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(sender).sendMessage(captor.capture());
    assertThat(removeColors(captor.getValue()), containsString("Unknown command"));
    verifyZeroInteractions(helpProvider);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)26 Test (org.junit.Test)24 Matchers.containsString (org.hamcrest.Matchers.containsString)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 CommandDescription (fr.xephi.authme.command.CommandDescription)20 CommandSender (org.bukkit.command.CommandSender)6 FoundResultStatus (fr.xephi.authme.command.FoundResultStatus)1