Small onCommand() bug

Discussion in 'Plugin Development' started by klosjaarrr, Oct 19, 2014.

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

    klosjaarrr

    Hey everyone,

    It is getting a bit late and I'm overseeing a small bug. I have an onCommand() class that looks like this:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2.  
    3. if (!cmd.getName().equalsIgnoreCase("staff")) {
    4. return false;
    5. }
    6.  
    7. if (!(sender instanceof Player)) {
    8. return false;
    9. }
    10.  
    11. Player p = (Player) sender;
    12.  
    13. // Do stuff
    14. return true;
    15.  
    16. }


    I have registered the command "staff" in my plugin.yml, but whenever I type in /staff in chat it just shows a white, blank "/staff". My plugin.yml looks like this:

    Code:
    name: StaffPlugin
    main: com.kevinvoorn.staffplugin.StaffPlugin
    author: Klosjaarrr
    version: 1.0.0
    description: Allows players to see online admin
     
    commands:
      staff:
          description: Shows a list of online admins
          usage: /<command>
          aliases: [admins]
    What am I doing wrong?
     
  2. Offline

    teej107

    klosjaarrr
    Code:java
    1. if (!cmd.getName().equalsIgnoreCase("staff")) {
    2. return false;
    3. }
     
  3. Offline

    klosjaarrr


    Still get the same error... It just returns a false whenever I type /staff for some reason... I have no idea why.
     
  4. Offline

    teej107

    klosjaarrr That was code from your code. Let me narrow down to your problem a bit more.
    Code:java
    1. !cmd.getName().equalsIgnoreCase("staff")


    !
     
  5. Offline

    klosjaarrr

    I still don't get it to work. I tried the following 2 methods, but got same results:

    Code:java
    1. if (!(cmd.getName().equalsIgnoreCase("staff"))) {
    2. return false;
    3. }

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("staff")) {
    2. // Do stuff
    3. return true;
    4. }
    5.  
    6. return false;
     
  6. Offline

    teej107

    klosjaarrr Unless you want to block out all of your other plugin commands, just check to see if the command is rather than isn't. As for your problem, if this is in another class, you need to set the command's command executor to that class.
     
    klosjaarrr likes this.
  7. Offline

    drpk

    klosjaarrr I had this problem, anyway, don't forget to use CommandExecutor and getCommand
     
  8. Offline

    teej107

    drpk returning true signifies that the command was successfully executed. returning false means that it wasn't.
     
  9. Offline

    klosjaarrr


    Ah, I forgot to add the command executor.. Thanks, it is fixed now :)
     
Thread Status:
Not open for further replies.

Share This Page