mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-30 13:08:00 +01:00
Added support for viewing in-depth help via /plan ?
This commit is contained in:
parent
6c8a9f9294
commit
38bb87b9b2
@ -47,14 +47,29 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
return new Builder(locale);
|
return new Builder(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Subcommand> getPermittedSubcommands(CMDSender sender) {
|
||||||
|
return subcommands.stream().filter(sender::hasAllPermissionsFor).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public void onHelp(CMDSender sender, Arguments arguments) {
|
public void onHelp(CMDSender sender, Arguments arguments) {
|
||||||
List<Subcommand> hasPermissionFor = subcommands.stream().filter(sender::hasAllPermissionsFor).collect(Collectors.toList());
|
List<Subcommand> hasPermissionFor = getPermittedSubcommands(sender);
|
||||||
sender.buildMessage()
|
sender.buildMessage()
|
||||||
.addPart(locale.getString(CommandLang.HEADER_HELP, getPrimaryAlias()))
|
.addPart(locale.getString(CommandLang.HEADER_HELP, getPrimaryAlias()))
|
||||||
.newLine().newLine()
|
.newLine().newLine()
|
||||||
.apply(new HelpFormatter(sender, colors, getPrimaryAlias(), hasPermissionFor)::addSubcommands)
|
.apply(new HelpFormatter(sender, colors, getPrimaryAlias(), hasPermissionFor)::addSubcommands)
|
||||||
.newLine().newLine()
|
.newLine().newLine()
|
||||||
.addPart(locale.getString(CommandLang.FOOTER_HELP))
|
.addPart(locale.getString(CommandLang.FOOTER_HELP, getPrimaryAlias()))
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInDepthHelp(CMDSender sender, Arguments arguments) {
|
||||||
|
List<Subcommand> hasPermissionFor = getPermittedSubcommands(sender);
|
||||||
|
sender.buildMessage()
|
||||||
|
.addPart(locale.getString(CommandLang.HEADER_HELP, getPrimaryAlias()))
|
||||||
|
.newLine().newLine()
|
||||||
|
.apply(new HelpFormatter(sender, colors, getPrimaryAlias(), hasPermissionFor)::addInDepthSubcommands)
|
||||||
|
.newLine().newLine()
|
||||||
|
.addPart(locale.getString(CommandLang.FOOTER_HELP, getPrimaryAlias()))
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +91,10 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
String alias = gotAlias.get();
|
String alias = gotAlias.get();
|
||||||
if ("help".equals(alias)) {
|
if ("help".equals(alias)) {
|
||||||
onHelp(sender, arguments);
|
onHelp(sender, arguments);
|
||||||
|
return;
|
||||||
|
} else if ("?".equals(alias)) {
|
||||||
|
onInDepthHelp(sender, arguments);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
for (Subcommand subcommand : subcommands) {
|
for (Subcommand subcommand : subcommands) {
|
||||||
if (subcommand.getAliases().contains(alias)) {
|
if (subcommand.getAliases().contains(alias)) {
|
||||||
|
@ -78,6 +78,43 @@ public class HelpFormatter {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageBuilder addInDepthSubcommands(MessageBuilder message) {
|
||||||
|
MessageBuilder toReturn = message;
|
||||||
|
String m = colors.getMainColor();
|
||||||
|
String s = colors.getSecondaryColor();
|
||||||
|
String asString = subcommands.stream()
|
||||||
|
.filter(cmd -> cmd.getDescription() != null)
|
||||||
|
.map(cmd -> {
|
||||||
|
TextStringBuilder builder = new TextStringBuilder(
|
||||||
|
m + mainCommand + " " + cmd.getPrimaryAlias()
|
||||||
|
);
|
||||||
|
for (String description : cmd.getInDepthDescription()) {
|
||||||
|
builder.append("***").append(s).append(description).append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Subcommand.ArgumentDescriptor argument : cmd.getArguments()) {
|
||||||
|
builder.append("***").append(m).append(argument.isRequired() ? '<' + argument.getName() + '>' : '[' + argument.getName() + ']')
|
||||||
|
.append(s).append(" ").append(argument.getDescription()).append('\n');
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
|
||||||
|
.toString();
|
||||||
|
List<String[]> table = sender.getFormatter().tableAsParts(asString, "***");
|
||||||
|
|
||||||
|
for (String[] row : table) {
|
||||||
|
if (sender.isPlayer()) {
|
||||||
|
toReturn = toReturn.addPart(m + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
toReturn = toReturn.addPart(row[0]);
|
||||||
|
if (row.length > 1) toReturn = toReturn.addPart(row[1]);
|
||||||
|
toReturn = toReturn.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> argumentsAndAliases(Subcommand subcommand, List<Subcommand.ArgumentDescriptor> descriptors, Set<String> aliases) {
|
private List<String> argumentsAndAliases(Subcommand subcommand, List<Subcommand.ArgumentDescriptor> descriptors, Set<String> aliases) {
|
||||||
List<String> lines = new ArrayList<>();
|
List<String> lines = new ArrayList<>();
|
||||||
lines.add(colors.getMainColor() + subcommand.getPrimaryAlias() + colors.getTertiaryColor() + " Arguments:" + (descriptors.isEmpty() ? " none" : ""));
|
lines.add(colors.getMainColor() + subcommand.getPrimaryAlias() + colors.getTertiaryColor() + " Arguments:" + (descriptors.isEmpty() ? " none" : ""));
|
||||||
|
@ -72,7 +72,7 @@ public enum CommandLang implements Lang {
|
|||||||
LINK_REGISTER("Cmd - Link Register", "Register page: "),
|
LINK_REGISTER("Cmd - Link Register", "Register page: "),
|
||||||
|
|
||||||
HEADER_HELP("Cmd Header - Help", "> §2/${0} Help"),
|
HEADER_HELP("Cmd Header - Help", "> §2/${0} Help"),
|
||||||
FOOTER_HELP("Cmd Footer - Help", "§7Hover over command or arguments to learn more about them."),
|
FOOTER_HELP("Cmd Footer - Help", "§7Hover over command or arguments or use '/${0} ?' to learn more about them."),
|
||||||
HEADER_SEARCH("Cmd Header - Search", "> §2${0} Results for §f${1}§2:"),
|
HEADER_SEARCH("Cmd Header - Search", "> §2${0} Results for §f${1}§2:"),
|
||||||
HEADER_ANALYSIS("Cmd Header - Analysis", "> §2Analysis Results"),
|
HEADER_ANALYSIS("Cmd Header - Analysis", "> §2Analysis Results"),
|
||||||
HEADER_INFO("Cmd Header - Info", "> §2Player Analytics"),
|
HEADER_INFO("Cmd Header - Info", "> §2Player Analytics"),
|
||||||
|
Loading…
Reference in New Issue
Block a user