"Unknown command" but registered in the plugin.yml

Discussion in 'Plugin Development' started by Monkey_Swag, Jan 5, 2014.

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

    Monkey_Swag

    So I am trying to create a plugin, and one of my classes (the help page) is not working. When I type the command in-game it says "unknown command, type /help for help" and it is registered in the plugin.yml, because when I type sim *then click tab* it converts to "/SimplePots Help" anyone know what's wrong? Also, if you need my plugin.yml as well, tell me, however I feel it would be useless to post it.
    Code:java
    1. package me.Monkey_Swag.SimplePots;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class HelpPage extends JavaPlugin{
    10.  
    11. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    12. Player player = (Player) sender;
    13.  
    14. String white = ChatColor.WHITE + "";
    15. String green = ChatColor.GREEN + "";
    16. String dblue = ChatColor.DARK_BLUE + "";
    17. String blue = ChatColor.BLUE + "";
    18.  
    19.  
    20. if(cmd.getName().equalsIgnoreCase("SimplePots help") || cmd.getName().equalsIgnoreCase("sp help")) {
    21. player.sendMessage(dblue + "[" + blue + "SimplePots" + dblue + "]" + green + "-={" + white + "SimplePots Help" + green + "}=-");
    22.  
    23. }
    24.  
    25. return false;
    26.  
    27. }
    28. }
    29.  
     
  2. Offline

    Ambamore2000

    In
    Code:
        if(cmd.getName().equalsIgnoreCase("SimplePots help") || cmd.getName().equalsIgnoreCase("sp help")) {
    It can be because of the "SimplePots help". I don't know how to fix that, so I recommend "SimplePots_help" instead. --There will be someone who will tell you how to--
     
  3. Offline

    Monkey_Swag

    exactly! I did another test plugin, and I had to do one word to bring up the help page, it wouldn't work with two!
     
  4. Offline

    Ambamore2000

    Monkey_Swag
    Yes, but don't make this topic solved. If there is a way to make it so you can do 2 words, then let it unsolved. I had this problem, asking myself "Why is this happening", so I tried multiple things, and this is the reason. Happy to hear your problem is solved for now. :D
     
  5. Offline

    Xephiro

    Wouldn't work with two words because the second word is and argument if you look the args array at the position 0 you have the second word "help" and your command is "SimplePots"
     
  6. Offline

    Monkey_Swag

    The_Doctor_123
    You seem to have helped me on other things, mind giving me a hand on this? ;D
     
  7. Offline

    The_Doctor_123

    Monkey_Swag
    I am no longer providing my helping services around these forums. I'm still debating on that, but it's likely I won't be helping here again. But since you requested, I'll lend you a hand.

    A command is defined as the first word, then an array of arguments follow it. So you really want to check if the command is "SimplePots" or "sp" then check the first argument to see if it's "help". Hint: The arguments are in the String[] you named as "args".
     
  8. Offline

    Monkey_Swag

    The_Doctor_123
    So you are saying that I have to check if the first argument is "help" to make this work?
    For example:
    if(arg1 == help) {
    p.sendMessage(bla bla bla);
    }
    Would that make it work? (Cant test atm b/c I am at school :p)
     
  9. Offline

    Bart

    Check the length of 'args' but yes, if(args[0].equalsIgnoreCase("help"))..
     
  10. Offline

    The_Doctor_123

    Monkey_Swag
    Do you understand how arrays work?

    By the way, the == operator only compares values with primitive types, not objects. Using that operator would check if two references to an object are the same.
     
Thread Status:
Not open for further replies.

Share This Page