Solved Registering commands in different class

Discussion in 'Spigot Plugin Development' started by DoggyPlayss, Feb 17, 2020.

  1. Hello!
    I am using 1.12.2 spigot
    I have made couple of commands for testing and now i wanted to instead of registering them in main class, i make an EnableCommands class. I added all the commands to EnableCommands class but the getCommand is highlighted with red and i am told that it cannot resolve method "getCommand" in "Plugin".
    Can someone tell me what i did wrong and how i could fix it?
    Code (Java):
    public class EnableCommands {

        public static void enable(Plugin plugin){

            plugin.getCommand("gmc").setExecutor(new Gmc());
            plugin.getCommand("gms"). setExecutor(new Gms());
            plugin.getCommand("gma"). setExecutor(new Gma());
            plugin.getCommand("gmsp"). setExecutor(new Gmsp());
            plugin.getCommand("openinv"). setExecutor(new Openinv());


    Code (Java):
    public class Core extends JavaPlugin implements Listener {

        public void onEnable() {

            getServer().getConsoleSender().sendMessage(GREEN + "\n\nPlugin has been enabled!\n");
            getServer().getPluginManager().registerEvents(new OnJoin(), this);

        public void onDisable() {
            getServer().getConsoleSender().sendMessage(DARK_RED + "\n\nPlugin has been disabled!\n");


    Attached Files:

  2. Just put those in onEnable in your main class
  3. I want it to be in seperate class. Atm i dont need to but if i have lot more commands i would like to know how to do it and what i did wrong there.
  4. That might be the case because the Plugin interface does not have this method as you can see in the Javadoc. Simply take a JavaPlugin as parameter instead.

    However, the idea of registering them in another class does not seem to be good practice.