diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/use/CommandWithSubcommands.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/use/CommandWithSubcommands.java index d9ac69a34..a264c72a3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/use/CommandWithSubcommands.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/use/CommandWithSubcommands.java @@ -47,14 +47,29 @@ public class CommandWithSubcommands extends Subcommand { return new Builder(locale); } + private List getPermittedSubcommands(CMDSender sender) { + return subcommands.stream().filter(sender::hasAllPermissionsFor).collect(Collectors.toList()); + } + public void onHelp(CMDSender sender, Arguments arguments) { - List hasPermissionFor = subcommands.stream().filter(sender::hasAllPermissionsFor).collect(Collectors.toList()); + List hasPermissionFor = getPermittedSubcommands(sender); sender.buildMessage() .addPart(locale.getString(CommandLang.HEADER_HELP, getPrimaryAlias())) .newLine().newLine() .apply(new HelpFormatter(sender, colors, getPrimaryAlias(), hasPermissionFor)::addSubcommands) .newLine().newLine() - .addPart(locale.getString(CommandLang.FOOTER_HELP)) + .addPart(locale.getString(CommandLang.FOOTER_HELP, getPrimaryAlias())) + .send(); + } + + public void onInDepthHelp(CMDSender sender, Arguments arguments) { + List 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(); } @@ -76,6 +91,10 @@ public class CommandWithSubcommands extends Subcommand { String alias = gotAlias.get(); if ("help".equals(alias)) { onHelp(sender, arguments); + return; + } else if ("?".equals(alias)) { + onInDepthHelp(sender, arguments); + return; } else { for (Subcommand subcommand : subcommands) { if (subcommand.getAliases().contains(alias)) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/use/HelpFormatter.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/use/HelpFormatter.java index 5b73986d3..6522b566d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/use/HelpFormatter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/use/HelpFormatter.java @@ -78,6 +78,43 @@ public class HelpFormatter { 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 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 argumentsAndAliases(Subcommand subcommand, List descriptors, Set aliases) { List lines = new ArrayList<>(); lines.add(colors.getMainColor() + subcommand.getPrimaryAlias() + colors.getTertiaryColor() + " Arguments:" + (descriptors.isEmpty() ? " none" : "")); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/CommandLang.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/CommandLang.java index 4807d07d9..d96b5adde 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/CommandLang.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/CommandLang.java @@ -72,7 +72,7 @@ public enum CommandLang implements Lang { LINK_REGISTER("Cmd - Link Register", "Register page: "), 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_ANALYSIS("Cmd Header - Analysis", "> §2Analysis Results"), HEADER_INFO("Cmd Header - Info", "> §2Player Analytics"),