Solved Having problems with a for loo

Discussion in 'Plugin Development' started by Pacothegint, Nov 19, 2014.

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

    Pacothegint

    I just don't know how to split the list into different strings of player names.
    for example this is what i want it to do
    Code:
    owner
     
    player1
     
    player2
     
    player3
    
    what it does
    Code:
    owner
     
    player1
     
    player1
     
    player1
    
    This is my code
    Code:java
    1.  
    2. for(Player player:Bukkit.getOnlinePlayers()){
    3. if(plugin.permission.playerInGroup(player, string))
    4. {
    5. p.sendMessage(player.getName());
    6. event.setLine(1, player.getName());
    7. event.setLine(2, player.getName());
    8. event.setLine(3, player.getName());
    9. }
    10. }
    11.  


    I know why it replaces the second and third lines i just don't know how to stop it
     
  2. Offline

    davidp027

    try break; ?
     
  3. Offline

    Pacothegint

    davidp027
    If i break out of the code wont that just ignore the other lines that set the lines?
     
  4. Offline

    pookeythekid

    Pacothegint Firstly, I'm not sure how this is supposed to work if more than three players in the specified group are online. You wouldn't have enough room on the sign for that. But if three or fewer of the defined group are online, make a counter to keep track of how many lines you've gone over, so you can know which individual line to set (instead of setting all of them to each player you iterate over, like you're currently doing, hence the repeating player1).
    Code:java
    1. int lineCount = 1;
    2. for(Player player : Bukkit.getOnlinePlayers()) {
    3. if(plugin.permission.playerInGroup(player, string)) {
    4. if (i > 3)
    5. break; // Break out of the loop so you don't get an exception if you try setting line 5 (line 4, in terms of arrays), since that line won't exist on the sign.
    6. p.sendMessage(player.getName());
    7. event.setLine(lineCount, player.getName());
    8. lineCount++;
    9. }
    10. }
     
  5. Offline

    Pacothegint

    pookeythekid
    wow how did i not think of that. Thanks for the help though.
     
  6. Offline

    pookeythekid

Thread Status:
Not open for further replies.

Share This Page