Assigning the executor for the enchant command

We are almost ready to start using the command on the server. The only remaining step is to assign the class that we just wrote to the enchant command. This is typically referred to as registering a command. In the onEnable method of the Enchanter class, we will get the enchant command using the getCommand("enchant") code.

Tip

The name of the command must be exactly as it is in plugin.yml. This also means that this code will only retrieve commands that are specific to this plugin.

Once we have the enchant command, we can set a new instance of EnchantCommand as the executor for the command. All of this can be done in one line, as shown in the following piece of code:

getCommand("enchant").setExecutor(new ...

Get Building Minecraft Server Modifications - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.