Skip to content

Annotations and you

Dalton edited this page Apr 24, 2022 · 3 revisions

The annotations in this API are critical for 2 things:

The @RegisterCommand or @CommandName Annotations handle the automatic command registration. When you initialize the API using your plugin's main class the API will search for classes extending ApiCommand that have one of these 2 Annotations, once it has that it will search for aliases, description, and usage message.

How do I specify Description, Usage Message, and Aliases with Annotations?

Very simple:

If you are using the @RegisterCommand Annotation, you can simply add these fields to it:

@RegisterCommand(
        name = "yourcommandnamehere",
        description = "A command that does something",
        usageMessage = "/<command>",
        aliases = {"alias1", "alias2"}
)

These are pretty self-explanatory, hopefully. Do note, that everything but the name field is optional, if not set they will simply be empty.

If you want to use the @CommandName Annotation, you need to add the other Annotations:

@CommandName(name = "help")
@CommandDescription(description = "A command that does something")
@CommandUsage(usageMessage = "/<command>")
@CommandAliases(aliases = { "alias1", "alias2"})

These are pretty self-explanatory, hopefully. Do note, that everything but the @CommandName interface is optional.

While there is code to handle when a mix of both Annotation methods exists, it's highly recommended you either use @RegisterCommand or the second option using a combination of @CommandName and the other Annotations. Both methods work the same way, just some users may prefer one option over the other.