Noob Question

Discussion in 'Plugin Development' started by Lactem, Feb 1, 2013.

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

    Lactem

    I know this is a noob question, but I don't understand why if
    (commandlabel.equalsIgnoreCase("sz")) {
    if (args[0] == "join") {
    player.teleport(new Location(world, x1, y1, z1));
    player.sendMessage(ChatColor.GREEN + "You have joined sz!");
    }
    }
    isn't working. Its supposed to tell the player "You have joined sz!" whenever they type /sz join. There are no errors, but when I type /sz join, it says "unknown command." Please help.

    Thanks,
    Lactem
     
  2. Offline

    RealDope

    Put it in you plugin.yml
     
  3. Offline

    Lactem

    -_- It is in my plugin.yml. Perhaps the format is wrong? I have it like this:

    commands:
    sz join:
    description: makes you join sz
    usage: /sz join

    (The spacing is correct, but bukkit forums won't let me space it how I please.)
     
  4. Offline

    RealDope

    yep 100% wrong.

    Code:
    name: PluginName
    main: package.name.to.main.class
    version: 1.0
     
    commands:
      sz:
        description: Alias for sz
        usage: /sz
    
     
  5. Offline

    Lactem

    Thanks. I'll try that out. By the way, I have the name, main, and version, but I didn't see it necessary to include them, as the problem was with commands. Also, what about the join part of /sz join?
     
  6. Offline

    RealDope

    The actual command is just /sz. The arguments are everything that comes after it. So in plugin.yml you just put the first word.
     
  7. Offline

    Lactem

    I understand, but then where would I put my argument? Here is my code:

    if (cmd.getName().equalsIgnoreCase("sz")) {
    if ((args.length >= 1) && (args[0] == ("join"))) {
    if (args.length == 1) {
    player.teleport(new Location(world, x1, y1, z1));
    player.sendMessage(ChatColor.GREEN + "You have joined sz!");
    return true;
    }
    }
    }
     
  8. Offline

    welsar55

    dont put the arg anywhere
     
  9. Offline

    Lactem

    Could you please give me an example of what it should look like? If I just leave it at if (cmd.getName().equalsIgnoreCase("join")), then it won't work. Its the same if I leave it at (cmd.getName().equalsIgnoreCase("sz")).
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    Commang.getName return the name of the command as declared in the plugin.yml
     
  11. Offline

    Lactem

    What do you mean "return the name of the command as declared in the plugin.yml?" Do you just want me to give you my whole code and you tell me what to do differently?
     
  12. Offline

    Sagacious_Zed Bukkit Docs

    You wrote your plugin.yml, you should know what you have under commands.
     
  13. Offline

    Lactem

    Yeah, but I want my command to have a space between "sz" and "join." That isn't working out so well...
     
  14. Offline

    Sagacious_Zed Bukkit Docs

    Currently commands must be one word.
    All following words become parameters to the command.
     
  15. Offline

    Lactem

    So how do I make the parameters?
     
  16. Offline

    Sagacious_Zed Bukkit Docs

    When you use a command in game, you type them with your command.


    As for how you process them, they are passed in as the String array when your onCommand is called.
     
  17. Offline

    Lactem

    Could you tell me the code for that, please?
     
  18. Offline

    Sagacious_Zed Bukkit Docs

    As defined by the CommandExecutor interface. onCommand methods must have the following signature.
    Code:
    onCommand(CommandSender sender, Command command, String label, String[] args)
    Parameters, are another name for arguments, shortened to args. If you cannot process a String array, I recommend you read this
     
  19. Offline

    Lactem

    AAAHHH!!! I know! I have all of this, but how do I make someone be able to type /sz join?
     
  20. Offline

    RealDope

    plugin.yml:

    Code:
    commands:
      sz:
        description: blah
        usage /<command>
    
    Code:JAVA
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if(cmd.getName().equalsIgnoreCase("sz") {
    4. if(sender instanceof Player) {
    5. if(args[0].equalsIgnoreCase("join") {
    6. // player typed /sz join
    7. }
    8. }
    9. }
    10. }
    11.  
     
  21. Offline

    Sagacious_Zed Bukkit Docs

    anyone playing is always able to type that in their chat....

    Lactem, put that in code or syntax tags....

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

    Lactem

    How do I put that in code? Also, many thanks to RealDope. I finally got it!
     
  23. Offline

    beastman3226

    I'd make another if-statement checking if there is an argument.
     
  24. Offline

    caseif

    -.-
    You could have just checked the commandLabel...
     
  25. Offline

    Lactem

    Nope. I sure couldn't have.
     
Thread Status:
Not open for further replies.

Share This Page