Commands register, but not execute!

Discussion in 'Plugin Development' started by Zaros, Jun 12, 2011.

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

    Zaros

    On one of the plugins I'm working on, I'm having issues with commands. It only returns the 'usage' from the plugin.yml. It also returns a "onPlayerCommandPreprocess has been replaced with a new signature, (PlayerCommandPreprocessEvent)", which I also cannot seem to figure out. I have the source on pastebin right here:

    ACTRL.java
    ACTRLPlayerListener.java
     
  2. Offline

    nickguletskii

    Do not use the onPlayerCommandPreprocess event. Add command executors.
     
  3. Offline

    Zaros

    Wha.... (I'm still learning the terms for things)?

    Aren't those command executors in the PlayerListener?
     
  4. Offline

    nickguletskii

    No. I would show you how to use them, but I haven't got much time right now. Try looking at CommandBook's sourcecode.
     
  5. Offline

    Zaros

    Viewing, but its a bit extensive for some one at my level.

    Edit: I'm still not catching what I'm looking for.
     
  6. Offline

    nickguletskii

    All you need is a class implementing CommandExecutor. You need to add the command to plugin.yml, and add in the onEnable method of your main class:
    getServer().getPluginCommand("nameofthecommand").setExecutor(new YourExecutor());
     
  7. Offline

    Zaros

    So.... what goes at 'YourExecutor'. I still don't know what is defined as an Executor.

    Edit: 'Im having more problems with the Executor class than I did before I knew about them...
     
  8. Offline

    nickguletskii

    YourExecutor is the class implementing CommandExecutor.
     
  9. Offline

    ZephyrSigmar

    Ok then let me clean it up a little bit.
    You need to create a new class (in the same package ofc) and implement command executor after it+define the plugin.
    Something like this:
    Code:
    public class yourcommandexecutorclassname implements CommandExecutor{
    private final yourpluginsclassname plugin;
    public yourcommandexecutorclassname(yourpluginsclassname plugin){
    this.plugin=plugin
    }
    Then you should start to write in the commands:
    Code:
    public boolean onCommand(CommandSender sender,Command cmd,String cmdLayout,String[] args){
    if(cmdLayout.equalsIgnoreCase("thecommandwhatyouwant"){
    /*If you want to know how to get words after this command now i show it to you.
     *The string args means how many word is the sended command
     *So first of all we should check the commands lenght
     *Now i going to make a 2 word command(the command and one word)
     */
    if(args.lenght==1){
    if(args[0].equalsIgnoreCase("secondword"){
    //Here comes your stuff
    }
    }
    return false;
    }
    If you want to check if the command equals hello then u should simply write after the equalsIgnoreCase("hello") not ("/hello")!
    Care,the cmdLayout and the args are other things.
    DONT place / before the commands name.
    The command is what player type in,like: /hello
    But if the player type in this: /hello world
    Then the command is hello and the world is the first (args[0]) args.
    When you finished everything in the commandexecutor go back to your main file and write in the onEnable()
    Code:
    getCommand("commandnamelikehello").setExecutor(new yourexecutorsclassname(this);
    After you done this go to the plugin.yml and write in some lines:
    Code:
    commands:
       yourcommandname:
          description: You can add description if you want.My awesome command
          usage: <command>
    Before the yourcommandname you need to hit 3 space,and before the description and usage again +3 (totally 6).
    Dont replace the <command> with your,its fine!
    I hope i able to help,pm me if you need more help.
     
    Wesnc, Babarix and Zaros like this.
  10. Offline

    Zaros

    You explained it very well, and I now have it working. I'll have a lot of questions for this plugin, as its definitely out of my league(at least for now). I'll send you a PM about a few questions I have, mostly about logging arguments and other implementations.

    Thanks for the help, both of you. :)
     
Thread Status:
Not open for further replies.

Share This Page