Problem with a command being executed whenever any other command is executed

Discussion in 'Plugin Development' started by Njol, Apr 21, 2012.

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

    Njol

    I have a weird problem:
    The first command I register with commandMap.register("/", command) is always executed whenever i type any command, even non-existing ones, except for when I type a command I registered the same way as the first.
    Does anyone have a clue why this happens? Should I use PlayerCommandPreProcess instead? Or should I add a void command as first command (i.e. one that does nothing but return true)?
     
  2. Offline

    Musaddict

    Best way to do it (imo) is to make a new commands class (if you havent already), have it implement CommandExecutor, and register the class in your onEnable.

    The register should look like this:
    Code:java
    1.  
    2. getCommand("yourCommand").setExecutor(new CommandsClassNameHere());
    3.  

    Keep in mind that "yourCommand" should NOT have the slash in it, and should be lower case.

    Then in your commands class, the class definition should look like this:
    Code:java
    1.  
    2. public class CommandsClassNameHere implements CommandExecutor {
    3.  


    Lastly, you need to register the command in your plugin.yml
    Code:
    commands:
      yourCommand:
        description: Your command description here.
        usage: |
            /<command> help
    
    Again, "yourCommand" in this case should be lower case. The "usage" section is what will be sent to the player when your command returns false.
     
  3. Offline

    Njol

    Maybe I shoud have pointed that out: I cannot use the plugin.yml to register the commands, because the commands are parsed from text file(s) when the plugin loads, which can be created & modified freely by server admins. Thus I need a way to register commands at runtime, which I figured that using the plugin manager's command map was the best way, but now it doesn't seem to work correctly.

    I tried adding a void command just after getting the command map, but that doesn't seem to work. Also I just realized it's not actuall the first command I add, but the second. I have no idea why, the only difference i can see is that it doesn't have any aliases defined.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
Thread Status:
Not open for further replies.

Share This Page