Noob Question.

Discussion in 'Plugin Development' started by Jurre1996, Aug 26, 2012.

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

    Jurre1996

    Hello,
    This is me code, I'm doing something wrong, but I Dont know what.

    Couse if a user has permission to monsterparty.create and monsterparty.join then it works. But when someone only has the permission monsterparty.join It does not work. Im pritty sure I'm doing something wrong. Could anyone help me?

    Code:
    public boolean execute(CommandSender sender, String[] split) {
    Player player = (Player) sender;
    player.sendMessage(ChatColor.RED + "                          Party Help");
    player.sendMessage(ChatColor.DARK_PURPLE + "-----------------------------------------------------");
    //check if user has permission to create party
    if (player.hasPermission("monsterparty.create")) {
    player.sendMessage(ChatColor.YELLOW + "/party create [Name] " + ChatColor.AQUA + "- Create a party");
    player.sendMessage(ChatColor.YELLOW + "/party create [Name] :p[Password] " + ChatColor.AQUA + "- Create Password Protected Party");
    player.sendMessage(ChatColor.YELLOW + "/party lock " + ChatColor.AQUA + "- Lock your party");
    //check if user has permission to join party
    if (player.hasPermission("monsterparty.join")) {
    player.sendMessage(ChatColor.YELLOW + "/party join [Name] " + ChatColor.AQUA + "- Join a party");
    //check if user has permission to leave party
    if (player.hasPermission("monsterparty.leave")) {
    player.sendMessage(ChatColor.YELLOW + "/party join [Name] " + ChatColor.AQUA + "- Join a party");
    return true;
    }}}
    return false;
    }
    
    http://pastebin.com/4s8gmMGE
    - Jurre
     
  2. Offline

    Njol

    All your if statements are nested, thus the if (player.hasPermission("monsterparty.join")) is only checked if player.hasPermission("monsterparty.join").

    If you used indentation properly you would have seen this issue immediately (In eclipse you can simply select the whole code with ctrl+A and then press crtl+I to fix the indentatin)

    Also read this: http://forums.bukkit.org/threads/the-power-of-indentation-write-easly-readable-code.95083/
    and this if you want to have nice code automatically: http://forums.bukkit.org/threads/how-to-make-eclipse-clean-up-format-your-code-for-you.78574/
     
  3. Offline

    Njol

  4. Yeah, i saw, but i didn't see your post before i posted so...:p
     
  5. Offline

    Jurre1996

    Oke, the crtl+I was really helpfull,

    But how do I make it so that there not nested?
     
  6. Code:java
    1. if(somecondition == true) {
    2. if(someother == true) {
    3. this is nested
    4. }
    5. }
    6.  
    7. if(somecondition == true) {
    8.  
    9. }
    10. if(someother == true) {
    11. this is not nested
    12. }
    13.  
     
  7. Offline

    Jurre1996

    Oke thanks :)
     
Thread Status:
Not open for further replies.

Share This Page