Set help command to short description and alternatives
- As discussed in https://github.com/AuthMe/AuthMeReloaded/pull/169
This commit is contained in:
@@ -15,11 +15,12 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static fr.xephi.authme.command.help.HelpSection.DETAILED_DESCRIPTION;
|
||||
import static fr.xephi.authme.command.help.HelpSection.SHORT_DESCRIPTION;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
@@ -171,19 +172,29 @@ public class HelpProvider implements Reloadable {
|
||||
}
|
||||
|
||||
private void printAlternatives(CommandDescription command, List<String> correctLabels, List<String> lines) {
|
||||
if (command.getLabels().size() <= 1 || correctLabels.size() <= 1) {
|
||||
if (command.getLabels().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.ALTERNATIVES) + ":");
|
||||
// Get the label used
|
||||
final String parentLabel = correctLabels.get(0);
|
||||
final String childLabel = correctLabels.get(1);
|
||||
|
||||
// Label with which the command was called -> don't show it as an alternative
|
||||
final String usedLabel;
|
||||
// Takes alternative label and constructs list of labels, e.g. "reg" -> [authme, reg]
|
||||
final Function<String, List<String>> commandLabelsFn;
|
||||
|
||||
if (correctLabels.size() == 1) {
|
||||
usedLabel = correctLabels.get(0);
|
||||
commandLabelsFn = label -> singletonList(label);
|
||||
} else {
|
||||
usedLabel = correctLabels.get(1);
|
||||
commandLabelsFn = label -> Arrays.asList(correctLabels.get(0), label);
|
||||
}
|
||||
|
||||
// Create a list of alternatives
|
||||
for (String entry : command.getLabels()) {
|
||||
if (!entry.equalsIgnoreCase(childLabel)) {
|
||||
lines.add(" " + CommandSyntaxHelper.getSyntax(command, asList(parentLabel, entry)));
|
||||
for (String label : command.getLabels()) {
|
||||
if (!label.equalsIgnoreCase(usedLabel)) {
|
||||
lines.add(" " + CommandSyntaxHelper.getSyntax(command, commandLabelsFn.apply(label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user