Command Question

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Dec 15, 2013.

Thread Status:
Not open for further replies.
  1. Why does this not work?

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("perm")){
    2. Player p2 = Bukkit.getServer().getPlayer(args[0]);
    3. if(args.length == 1){
    4. player.sendMessage(ChatColor.GREEN + "Congratulations you gave " + args[0] + "the permission " + args[1]);
    5.  
    6. p2.addAttachment((Plugin) this, args[1], true);
    7. }
    8. }
     
  2. Offline

    1Rogue

    Move the "Player p2" line within the "args.length" check.

    Otherwise post what isn't working about it.

    Also args length != index height, so if the length is one in an array, you can only go to an index of 0. To use array[1] it needs to be length 2 or more.
     
  3. Offline

    Webster56

    You should always make things inside an if statement, or you might make things that have no result because you wouldn't get inside the if statement.

    And then, args.length == 1 means that the last arg is args[0], not args[1]. Which means in your case that you won't get in the if statement if you write /perm <name> <permission>
     
Thread Status:
Not open for further replies.

Share This Page