diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index bc939f0bc..a586d1f37 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -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 players, List locations, BiConsumer 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 players, List locations) { + teleportUniform(players, locations, Entity::teleport); + } }