add UtilPlayer#teleportUniform
This commit is contained in:
parent
81db11a640
commit
16905240e9
@ -13,6 +13,8 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -1187,4 +1189,27 @@ public class UtilPlayer
|
||||
String getAudioPath();
|
||||
|
||||
}
|
||||
|
||||
public static void teleportUniform(List<Player> players, List<Location> locations, BiConsumer<Player, Location> teleport) {
|
||||
// Find the number of spaces between each player,
|
||||
int spacesBetween = Math.max(Math.floorDiv(locations.size(), players.size()), 1);
|
||||
int spaceIndex = 0;
|
||||
|
||||
// Teleport the players to locations every [spacesBetween] spaces
|
||||
for (Player player : players)
|
||||
{
|
||||
teleport.accept(player, locations.get(spaceIndex));
|
||||
|
||||
spaceIndex += spacesBetween;
|
||||
|
||||
if (spaceIndex > locations.size())
|
||||
{
|
||||
spaceIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void teleportUniform(List<Player> players, List<Location> locations) {
|
||||
teleportUniform(players, locations, Entity::teleport);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user