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;
}
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));
}
}
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 HelpProviderTest method shouldReplaceIncorrectLabels.
@Test
public void shouldReplaceIncorrectLabels() {
// given
List<String> labels = Arrays.asList("authme", "wrong");
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
// when
List<String> result = HelpProvider.filterCorrectLabels(command, labels);
// then
assertThat(result, contains("authme", "register"));
}
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>"));
}
Aggregations