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;
}
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);
}
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;
}
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);
}
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.");
}
Aggregations