Assigning the executor for the 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. In the onEnable()
method of our Enchanter
class we will get the enchant
command using the code getCommand("enchant")
.
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 specific to this plugin.
Once we have the 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 EnchantCommand());
All that you will have in your main class is shown in the following code:
package com.codisimus.enchanter; import org.bukkit.plugin.java.JavaPlugin; /** * Enchants the item that the command sender is holding */ public class Enchanter extends JavaPlugin { @Override public void onEnable() { //Assign...