Commands problem

Discussion in 'Plugin Development' started by Chlorek, Jun 4, 2012.

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

    Chlorek

    So, I have onCommand() method and it's not called when I type any command. All the time I see "usage" of my command. My onCommand():
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            //some code here - whatever I type it's not executed
            }
    My plugin.yml:
    Code:
    name: TwistedCornersTp
    main: com.gmail.chlorek.cl.TwistedCornersTp.TwistedCornersTp
    version: 1.0
    commands:
        twist:
            description: some description
            usage: /twist <player>
            permission: TwistedCornersTp.twist
            permission-message: You have not permission to use this command
    Please help, all other events work fine.
     
  2. when you see the usage then you probably return false where you should return true.
     
  3. Offline

    Chlorek

    Hmm but when everything in my command execution function it returns true. However should it execute everything before return?
     
  4. yes, since when you 'return' you "jump" out of the method meaning every piece of code afterwards in that method which might get executed won't run at all.
     
  5. Offline

    Chlorek

    So why the hell it doesn't work. All other events work. My onCommand() is not even called! I made simple test by sending some text to player that typed command and then it return true. It still show me usage and no code is executed!
     
  6. If you handle the command in your main class then i don't know. If you use a executor, however, make sure you've set it to the command you want to handle.
     
  7. Offline

    Chlorek

    I made that in another class file, I got my main class (TwistedCornersTp - just onEnable etc) and TpEvents class to listen and execute events. And what do you mean about setting this command I want handle?
     
  8. If you have a separate executor for a command you need to tell bukkit that that specific command is executed by a specific executor of yours.
    Code:
    getCommand(<command>).setExecutor(<executorinstance>);
    whereas <command> is the name of the command and <executorinstance> is an instance of you executor.
     
  9. Offline

    Chlorek

    Oh thank you, it works. That should be added to Plugin Tutorial (I am new to Java and Bukkit API), however I like to keep my code clean (like in c++) and I put right pieces of code to right source files.

    #Edit
    Oh sorry, I see it is on wiki (how did I read it before? :<)
     
Thread Status:
Not open for further replies.

Share This Page