Usage on all but a few commands?

Discussion in 'Plugin Development' started by nicholasntp, Mar 23, 2012.

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

    nicholasntp

    Ok guys, I'm thanking you all ahead of time for your help.

    Now.
    I had 2 plugins and merged them. Everything is set up, i fixed plugin.yml, added commands in, and everything. But all the commands I merged in to the plugin just automatically return false. The ones that already were there work perfectly. No console errors or anything. Just the usage message. Any ideas? Heres some code.


    Beginning:
    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. Player player = null;
    5. if (sender instanceof Player) {
    6. player = (Player) sender;
    7. }
    8.  


    What Works:

    Code:java
    1.  
    2. if (cmd.getName().equalsIgnoreCase("ntp")) {
    3. if (args.length == 0) {
    4. NTPServer.OnCmdNTP(player);
    5. }
    6.  


    What Doesnt Work:

    Code:java
    1.  
    2. if (cmd.getName().equalsIgnoreCase("test")) {
    3. player.sendMessage("Testing Confirmed.");
    4.  
    5. }
    6.  


    Any ideas on what could be going wrong? (I have more commands that work and dont work, but this is just part.)
     
    • registered commands properly in the plugin.yml?
    • set the executor of all commands correctly?
     
  2. Offline

    nicholasntp

    Yes.
    What do you mean? I put return true where it is supposed to return true, if that is what you're asking.
     
  3. Offline

    Technius

    If you have your onCommand method in a seperate class that implements CommandExecutor, make sure you set the command to that executor.
     
  4. Offline

    Lolmewn

    You registered the command "test"?
    I mean, if /ntp works, you could just do sender.sendMessage("Test"); there.
     
  5. Offline

    nicholasntp

    Its in the Main Class like it should be.
    Yes It's registered in the plugin.yml. My point is, one command works while the other doesnt. Same onCommand thing too.
     
  6. If you don't have the on command in you main class
    Code:
    getCommand("command_thats_not_working").setExecutor(the_class);
     
  7. Offline

    nicholasntp

     
  8. sry, over read that one. Well, posting the main/executor class and/or the plugin.yml would help a bit at least.
     
  9. Offline

    nicholasntp

    Its okay! I do stuff like that all the time. And sure... I just wanted my plugin to be semi private, so Ill post the stuff needed.

    MainClass (open)
    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. Player player = null;
    5. if (sender instanceof Player) {
    6. player = (Player) sender;
    7. }
    8. if (cmd.getName().equalsIgnoreCase("ntp")) {
    9. if (args.length == 0) {
    10. NTPServer.OnCmdNTP(player);
    11. }
    12. else if (args.length == 1){
    13. //ntp command
    14. }
    15. }
    16. if(cmd.getName().equalsIgnoreCase("ban")) {
    17. ------------------
    18. ------------------
    19. (This Works)
    20. ------------------
    21. ------------------
    22. }
    23. if (cmd.getName().equalsIgnoreCase("test")) {
    24. player.sendMessage("Testing Confirmed.");
    25.  
    26. }
    27.  


    And plugin.yml will be in next post.

    Code:yml
    1.  
    2. name: NTPServer
    3. main: me.nicholasntp.NTPServer.NTPServer
    4. version: 1.0dev
    5. author: nicholasntp
    6.  
    7. description:
    8. NTP Server's plugin.
    9.  
    10. commands:
    11. ntp:
    12. description: Does various things for The NTP Server.
    13. usage: Does various things for The NTP Server.
    14.  
    15. ban:
    16. description: Bans players
    17. usage: /ban (player) (reason)
    18.  
    19. test:
    20. description: A test
    21. usage: /test
    22.  
    23. ------------
    24.  


    Anyone?

    I am so confused on why it wont work. Anyone have any ideas?

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

    Technius

    When you want to do multiple checks for the same purpose(example: commands) use else if. I believe it improves performance slightly and makes your code nicer.

    Code:java
    1. if(condition1);
    2. else if(condition2);
    3. else if(condition3);
    4. else;
     
  11. Offline

    nicholasntp

    Good point, thank you. I will see if this solves my problem too.

    Thank you Technius! What you said made me look at my code, and I had a bracket error somewhere. Thank you for the tip too!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  12. So is the issue fixed, or still there?
     
  13. Offline

    Technius

    He said it's fixed.
     
  14. Offline

    nicholasntp

    Ahh sorry, but yeah, its fixed. Thanks all of you!
     
Thread Status:
Not open for further replies.

Share This Page