From 333cea3f47c614cb56ce9ee47d6523e8716898dd Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 23 Nov 2017 20:59:18 -0500 Subject: [PATCH] Fix players being teleported into blocks in BLD in the most overcomplicated way possible --- .../game/arcade/game/games/build/Build.java | 119 +++++++++++++++--- 1 file changed, 100 insertions(+), 19 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java index e536a6907..61bfb8d0e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java @@ -132,6 +132,7 @@ public class Build extends Game protected long _voteTime = 14000; protected long _viewTime = 18000; private BuildData _viewData = null; + private static final double TELEPORT_BORDER_DISTANCE = 1.0; private int _countdownTimerState = 0; @@ -735,30 +736,110 @@ public class Build extends Game return _buildStateTime == 0; } + private void teleportPlayer(Player player, Location loc) { + player.closeInventory(); + player.eject(); + player.leaveVehicle(); + player.teleport(loc); + player.setFlying(true); + } + public void teleportPlayers(BuildData data) { - //Teleport - for (int i=0 ; i edgeLocations = new ArrayList<>(); + + Location position = expandedBottomLeft.clone(); + + // Look directly forward + position.setPitch(0.0F); + + // Look in the general direction of the build, which is "up" from + // a bird's-eye view. + position.setYaw(-90); + + // Move across the bottom edge of the square, moving right + for (double x = position.getX(); x < expandedTopRight.getX(); x++) { + position.setX(x); + edgeLocations.add(position.clone()); + } + + // Yaw to "left" from birds-eye + position.setYaw(180); + + // Move across the right edge of the square, moving up + for (double z = position.getZ(); z < expandedTopRight.getZ(); z++) { + position.setZ(z); + edgeLocations.add(position.clone()); + } + + // Yaw to "down" from birds-eye + position.setYaw(90); + + // Move across the top edge of the square, moving left + for (double x = position.getX(); x > expandedBottomLeft.getX(); x--) { + position.setX(x); + edgeLocations.add(position.clone()); + } + + // Yaw to "right" from birds-eye + position.setYaw(0); + + // Move across the left edge of the square, moving down + for (double z = position.getZ(); z > expandedBottomLeft.getZ(); z--) { + position.setZ(z); + edgeLocations.add(position.clone()); + } + + Player[] players = UtilServer.getPlayers(); + + // Find the number of spaces between each player, + int spacesBetween = Math.max(Math.floorDiv(edgeLocations.size(), players.length), 1); + int spaceIndex = 0; + + // Teleport the players to locations every [spacesBetween] spaces + for (Player player : players) { - double lead = i * ((2d * Math.PI)/UtilServer.getPlayers().length); + teleportPlayer(player, edgeLocations.get(spaceIndex)); - double oX = -Math.sin(lead) * 26; - double oZ = Math.cos(lead) * 26; + spaceIndex += spacesBetween; - Location loc = data.Spawn.clone().add(oX, 0, oZ); - loc.setDirection(UtilAlg.getTrajectory(loc, data.Spawn)); - - // This is supposed to be a quick fix for players being teleported into blocks - // I am not sure the exact cause of this bug, it seems to happen when there is a specific amount of players - if (loc.getBlock() != null && loc.getBlock().getType() != Material.AIR) - loc.setY(loc.getWorld().getHighestBlockYAt(loc) + 1); - - UtilServer.getPlayers()[i].closeInventory(); - UtilServer.getPlayers()[i].eject(); - UtilServer.getPlayers()[i].leaveVehicle(); - UtilServer.getPlayers()[i].teleport(loc); - - UtilServer.getPlayers()[i].setFlying(true); + if (spaceIndex > edgeLocations.size()) + { + spaceIndex = 0; + } } }