[SOLVED] Commands problem

Discussion in 'Plugin Development' started by RTRD, Oct 7, 2011.

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

    KingAtomx

    Okay. Try using cmd.getName() instead
     
    Perdog likes this.
  2. Offline

    Perdog

    I could be wrong but I think label is for aliases isn't it?
     
  3. Offline

    RTRD

    Basically I want child commands. So does that work?
     
  4. Offline

    Perdog

    Define what you mean by child commands? I'm just a little off put by that..
     
  5. Offline

    RTRD

    like /mcdp is the main command and /mcdp help is another command under the first one... :)
     
  6. Offline

    Perdog

    Hmm ... No I think you still need to use
    Code:
    command.getName().equalsIgnoreCase("mcdp")
    like KingAtomx said.
     
  7. Offline

    RTRD

  8. Offline

    Perdog

    Then I am completely stumped :/ Everything looks okay.. Sorry man, I really hope you find the solution soon!
     
  9. Offline

    RTRD

    Thanks for the help! :D
     
  10. Offline

    oyasunadev

    Don't set any permission in plugin.yml.
     
  11. Offline

    Ahniolator

    I'm not sure exactly what the problem is, but I do know a solution. From my perspective on how I do commands, you should not specify arguments in the plugin.yml. You only need
    Code:yml
    1. commands:
    2. mdcp:
    3. description: example
    4. usage: /<command> <help>


    THEN, in your onCommand code, you would do something like this:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender cs, Command cmnd, String label, String[] args) {
    3. Player player = null;
    4.  
    5. if (cmnd.getName().equalsIgnoreCase("mdcp")) {
    6. String arg = "";
    7. String name = "";
    8.  
    9. if ((cs instanceof Player)) {
    10. player = (Player) cs;
    11. }
    12.  
    13. try {
    14. arg = args[0];
    15. //only return false here if you don't want /mdcp by itself to do anything,
    16. //otherwise just put whatever code you want to execute and return true
    17. return false;
    18. }
    19.  
    20. if (arg.equalsIgnoreCase("help")) {
    21. //do help stuff here
    22. return true;
    23. }
    24. if (arg.equalsIgnoreCase("version")) {
    25. //do version stuff here
    26. return true;
    27. }
    28. if (arg.equalsIgnoreCase("reload")) {
    29. //do reload stuff here
    30. return true;
    31. }
    32. //then finally return false if they didn't do it right
    33. return false;
    34. }


    This is very similar to what I do for all of my plugins, and it works just fine ;)
     
  12. Offline

    RTRD

    Removed.

    That still does not work for me. It is just showing in-game: /mcdp <help>
     
  13. Offline

    Ahniolator

    Is the onCommand code inside your main class?
     
  14. Offline

    RTRD

    Yep.

    EDIT!: No... xD
     
  15. Offline

    Ahniolator

    -edit- Okay! Now I know how to fix it :D

    Give me one minute to formulate it ;)

    You need to set the executor for each command INSIDE your onEnable within your main class like so:
    Code:java
    1. this.getCommand("mdcp").setExecutor(exampleCommandExecutorClassHere);


    Then, and only then, it will work if you're onCommand code is not inside the main class ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  16. Offline

    RTRD

    Skype? :p
     
  17. Offline

    Ahniolator

    Edit: Nvm, I just got yours :D
     
  18. Offline

    RTRD

  19. Offline

    Ahniolator

    You're welcome! :D

    It definitely took awhile :p
     
  20. Offline

    RTRD

    Yeah, 1 hour and 35 minutes to find a spelling mistake! xD
     
Thread Status:
Not open for further replies.

Share This Page