From 16905240e98a2014c7e1690cfd31b145b81c34e2 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 18 Dec 2017 13:35:29 -0500 Subject: [PATCH] add UtilPlayer#teleportUniform --- .../mineplex/core/common/util/UtilPlayer.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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); + } }