Add addon top level commands to BentoBox help

This enables admins to see which top level commands have been registered
under BentoBox. As these commands can be defined in config files, it is
not always obvious which one should be used so this help will be useful.
This commit is contained in:
tastybento 2020-05-08 14:19:50 -07:00
parent 9a517446c8
commit 11510b15fc
3 changed files with 49 additions and 9 deletions

View File

@ -17,13 +17,13 @@ import world.bentobox.bentobox.api.user.User;
*/
public class DefaultHelpCommand extends CompositeCommand {
private static final int MAX_DEPTH = 2;
private static final String USAGE_PLACEHOLDER = "[usage]";
private static final String PARAMS_PLACEHOLDER = "[parameters]";
private static final String DESC_PLACEHOLDER = "[description]";
private static final String HELP_SYNTAX_REF = "commands.help.syntax";
private static final String HELP_SYNTAX_NO_PARAMETERS_REF = "commands.help.syntax-no-parameters";
private static final String HELP = "help";
protected static final int MAX_DEPTH = 2;
protected static final String USAGE_PLACEHOLDER = "[usage]";
protected static final String PARAMS_PLACEHOLDER = "[parameters]";
protected static final String DESC_PLACEHOLDER = "[description]";
protected static final String HELP_SYNTAX_REF = "commands.help.syntax";
protected static final String HELP_SYNTAX_NO_PARAMETERS_REF = "commands.help.syntax-no-parameters";
protected static final String HELP = "help";
public DefaultHelpCommand(CompositeCommand parent) {
super(parent, HELP);
@ -81,7 +81,7 @@ public class DefaultHelpCommand extends CompositeCommand {
return true;
}
private void runSubCommandHelp(User user, int newDepth) {
protected void runSubCommandHelp(User user, int newDepth) {
for (CompositeCommand subCommand : parent.getSubCommands().values()) {
// Ignore the help command
if (!subCommand.getLabel().equals(HELP)) {
@ -92,7 +92,7 @@ public class DefaultHelpCommand extends CompositeCommand {
}
}
private boolean showPrettyHelp(User user, String usage, String params, String desc) {
protected boolean showPrettyHelp(User user, String usage, String params, String desc) {
// Show the help
if (user.isPlayer()) {
// Player. Check perms

View File

@ -23,6 +23,7 @@ public class BentoBoxCommand extends CompositeCommand {
new BentoBoxCatalogCommand(this);
new BentoBoxReloadCommand(this);
new BentoBoxLocaleCommand(this);
new BentoBoxHelpCommand(this);
// Database names with a 2 in them are migration databases
if (getPlugin().getSettings().getDatabaseType().name().contains("2")) {
new BentoBoxMigrateCommand(this);

View File

@ -0,0 +1,39 @@
package world.bentobox.bentobox.commands;
import java.util.Comparator;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.DefaultHelpCommand;
import world.bentobox.bentobox.api.user.User;
/**
* Lists help and commands registered by addons BentoBox.
*
* @author tastybento
* @since 1.14.0
*/
public class BentoBoxHelpCommand extends DefaultHelpCommand {
/**
* Custom help to show addon registered top level commands
* @param parent command parent
*/
public BentoBoxHelpCommand(CompositeCommand parent) {
super(parent);
}
@Override
public boolean execute(User user, String label, List<String> args) {
super.execute(user, label, args);
// Show registered addon commands
getPlugin().getCommandsManager().getCommands().values().stream()
.filter(cc -> cc.getAddon() != null)
.sorted(Comparator.comparing(CompositeCommand::getName))
.forEach(v -> showPrettyHelp(user, v.getUsage(),
user.getTranslationOrNothing(v.getParameters()),
user.getTranslationOrNothing(v.getDescription()) + " (" + v.getAddon().getDescription().getName() + ")"));
user.sendMessage("commands.help.end");
return true;
}
}