-
Notifications
You must be signed in to change notification settings - Fork 4
Command Captions
Mazen edited this page Apr 16, 2023
·
2 revisions
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
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);
You can easily send (custom) captions by doing this:
commandManager.captionRegistry().sendCaption(sender, context, key);
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);
I hope this wiki helped you with learning how to fully utilize mCommands