Teleporting players to spawn points around a map.

Discussion in 'Plugin Development' started by WolfMage1, Apr 20, 2017.

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

    WolfMage1

    My idea:

    Code:
    for (Player player : Bukkit.getOnlinePlayers()) {
        for (Location location : arena.getLocations()) {
            player.teleport(location);
        }
    }
    
    The problem with that is it will iterate over every location and then move to the next iteration in the player loop (if I understand nested for's right)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @WolfMage1 You do understand it right.
    Set a counter before the player loop, start it at 0.
    player.teleport(list.get(counter))
    counter = (counter+1)%list.size()
     
  3. Offline

    WolfMage1

    So something like this then?
    Code:
    int counter = 0;
    for (Player player : Bukkit.getOnlinePlayers()) {
        Location location = arena.getLocations().get(counter);
        player.teleport(location);
        counter++;
    }
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @WolfMage1 What if you have 5 locations and 10 players?
     
  5. Offline

    WolfMage1

    Game doesn't start if there's not enough spawns, although I guess that would be a decent fail-safe thing.
     
Thread Status:
Not open for further replies.

Share This Page