Command not being recognized

Discussion in 'Plugin Development' started by aman207, Jan 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    aman207

    I have registered the command in the plugin.yml and it is registered as an event in onEnable

    My main class

    Code:java
    1. package aman207.uni.me.cookit;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class CookIt extends JavaPlugin implements Listener {
    8.  
    9. public void onEnable()
    10. {
    11. Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
    12. }
    13.  
    14. public void onDisable()
    15. {
    16.  
    17. }
    18.  
    19. }
    20.  


    My CommandListener
    Code:java
    1. public class CommandListener implements Listener, CommandExecutor {
    2.  
    3. static CookIt plugin;
    4.  
    5. public CommandListener(CookIt config)
    6. {
    7. plugin = config;
    8. }
    9.  
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11. if(cmd.getName().equalsIgnoreCase("cook"))
    12. {
    13. Logger.getLogger("").info("Yesasdf");
    14. //Blah blah you don't need to see 200 lines of code


    When I type /cook, nothing happens in the console. I tried putting getLogger in the constructor for CommandListener and it did show a message, so I know it's being correctly registered in onEnable.

    Anybody know what's wrong? Thanks.
     
  2. Offline

    Xephiro

    I recomend to you split your CommandListener in one Executor Class and one Listener Class

    For use your executor class you need put the next
    Code:java
    1. @Override
    2. public void onEnable()
    3. {
    4. ....
    5. getCommand("command").setExecutor(new TheExecutorClass(this)); // This is for your command executor
    6. new TheListenerClass(this); //This is for your listener if you need it
    7. ....
    8. }
    9.  


    Don't forget put your commands in the plugin.yml file
     
  3. Offline

    Pew446

    Did you remember to put the command definition in plugin.yml? See here: http://wiki.bukkit.org/Plugin_YAML

    Nevermind that, too tired to read the first sentence of your post I guess :)
     
  4. Offline

    bigteddy98

    Try doing this:
    Code:java
    1. public void onEnable()
    2. {
    3. CommandListener commandListener = new CommandListener(this);
    4. this.getServer().getPluginManager().registerEvents(commandListener, this);
    5. this.getCommand("yourcommand").setExcecutor(commandListener);
    6. }
     
  5. Offline

    1Rogue

    You registered the command for being a listener, but you haven't registered it as a commandexecutor:

    Code:java
    1. CommandListener command;
    2. YourPlugin plugin;
    3. plugin.getCommand("cook").setExecutor(command);
     
  6. Offline

    aman207

Thread Status:
Not open for further replies.

Share This Page