Search code examples
javaeclipsepluginsminecraftbukkit

Bukkit Plugin: Can't import command


I started working on a bukkit plugin the other day with the aim to return hello in the text window when the user types in '/hello'. However this is not working, because I cannot import the command line in eclipse. Any suggestions? It says, "Command cannot be resolved to a type"

package me.Nickedyerpants;

import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class Plugin extends JavaPlugin{

@Override
public void onEnable(){     //what happens when plugin is enabled

    getLogger().info("First plugin starting up....");


}


@Override
public void onDisable(){   //for when plugin is disabled


    boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

        if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player){

            Player player = (Player) sender;

            player.sendMessage("hello");

        }

        return true;

    }



}

}

Solution

  • Your code is inccorect, you cannot implement onCommand inside of the onDisable method, plus you need to properly close your class with a curly bracket.

    Your class should look like this:

        @Override
        public void onDisable() {   
                // plugin is being disabled.
        }
    
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) {
    
                Player player = (Player) sender;
    
                player.sendMessage("hello");
    
            }
    
            return true;
    
        }
    

    While making sure to close the class with a closing curly bracket }.

    Tip: Defining methods should be within the class itself not inside another method.