Skip to content

Command Captions

Mazen edited this page Apr 16, 2023 · 2 revisions

Command Captions

To create a caption => firstly, we need to understand what is a caption

A caption is a message output to the command sender, each caption has it's own unique key identifying it

Creating Command Captions

First step: create the caption key example:

@NotNull
private final static CaptionKey SOME_ERROR_CAPTION = CaptionKey.of("execution.error");

Second step: Create the caption it's self example:

Caption<CommandSender> errorCaption = Caption.<CommandSender>builder(SOME_ERROR_CAPTION)
						.withMessage((sender, context, ex) -> Component.text("Some error, ugh idk !", NamedTextColor.RED)).build();

Third step: registering the caption in the command manager example:

commandManager.captionRegistry().registerCaption(errorCaption);

Sending captions

You can easily send (custom) captions by doing this:

commandManager.captionRegistry().sendCaption(sender, context, key);

Captions Exceptions

Sometimes captions may be based on command exceptions which already have a message to the user note: the exception must extend the class CommandException Here's an example on how to send caption due to an exception,

commandManager.captionRegistry().sendCaption(sender, context, exception, key);