Teams

Discussion in 'Plugin Development' started by Coopah, Apr 21, 2014.

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

    Coopah

    Ok, I'm completely puzzled here. How do I get all the online players then split them into 2 teams?
     
  2. Coopah
    ArrayList<String> team1 = new ArrayList<String>();
    ArrayList<String> team2 = new ArrayList<String>();
    Integer i -= 0;
    for(Player p : Bukkit.getOnlinePlayers()){
    if(i == 0){
    team1.add(p.getUUID().toString);
    i == 1;
    }else{
    team2.add(p.getUUID().toString);
    i == 0;
    }
    }

    *Wrote it here, havent tested, should work
     
  3. Offline

    Coopah

  4. Offline

    Rocoty

    Coopah but you should be able to fix them.

    One would consider using int instead of Integer. Assignment should be done with single =. toString is a method.
     
  5. Offline

    beeselmane

    Why can't you just store the players? (it's more accessible + you don't have to take up the time to do a username lookup (or UUID lookup (is that even a thing?))

    As shown here:
    Code:java
    1. ArrayList<Player> team1 = new ArrayList<Player>();
    2. ArrayList<Player> team2 = new ArrayList<Player>();
    3. int i = 0;
    4.  
    5. for (Player p : Bukkit.getOnlinePlayers())
    6. {
    7. if (i % 2 == 0)
    8. {
    9. team1.add(p);
    10. i++;
    11. } else {
    12. team2.add(p);
    13. i--;
    14. }
    15. }
     
  6. Rocoty Integer is tha best :3, Coopah and yea, as I said, wrote it here ... also the .getUniqueId().. :p
     
Thread Status:
Not open for further replies.

Share This Page