Skip to content

Command help

Revxrsal edited this page Sep 21, 2021 · 1 revision

Commands can get pretty nested and end-users may need a full look on all the available commands in which they can execute. Help commands are what get this job done.

Lamp comes with a basic API for generating help messages. The API allows for generating any value (strings, chat components, etc.) for each executable command.

The help API consists of two main classes:

  • CommandHelpWriter: You implement this in order to generate values for each executable command
  • CommandHelp: This is an extension of a java.util.List that contains iterable entries of all the values generated by the help writer, as well as useful methods for paginating results into pages and sections. This is usable as a command parameter.

Usage

All help writers must inherit from CommandHelpWriter, and should be registered with CommandHandler#setHelpWriter(CommandHelpWriter).

Example

commandHandler.setHelpWriter((command, actor) -> String.format("%s %s - %s", command.getPath().toRealString(), command.getUsage(), command.getDescription()));
@Command("something help")  
public void help(CommandActor actor, CommandHelp<String> helpEntries, @Default("1") int page) {  
    for (String entry : helpEntries.paginate(page, 7)) // 7 entries per page   
        actor.reply(entry);  
}