Fix players being teleported into blocks in BLD in the most overcomplicated way possible
This commit is contained in:
parent
46c8445f38
commit
333cea3f47
@ -132,6 +132,7 @@ public class Build extends Game
|
|||||||
protected long _voteTime = 14000;
|
protected long _voteTime = 14000;
|
||||||
protected long _viewTime = 18000;
|
protected long _viewTime = 18000;
|
||||||
private BuildData _viewData = null;
|
private BuildData _viewData = null;
|
||||||
|
private static final double TELEPORT_BORDER_DISTANCE = 1.0;
|
||||||
|
|
||||||
private int _countdownTimerState = 0;
|
private int _countdownTimerState = 0;
|
||||||
|
|
||||||
@ -735,30 +736,110 @@ public class Build extends Game
|
|||||||
return _buildStateTime == 0;
|
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)
|
public void teleportPlayers(BuildData data)
|
||||||
{
|
{
|
||||||
//Teleport
|
Location lowestLoc;
|
||||||
for (int i=0 ; i<UtilServer.getPlayers().length ; i++)
|
Location highestLoc;
|
||||||
|
|
||||||
|
// Find the lowest corner by comparing y-values
|
||||||
|
if (data.CornerA.getY() < data.CornerB.getY()) {
|
||||||
|
lowestLoc = data.CornerA;
|
||||||
|
highestLoc = data.CornerB;
|
||||||
|
} else {
|
||||||
|
lowestLoc = data.CornerB;
|
||||||
|
highestLoc = data.CornerA;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're going to expand the boundaries of the corners
|
||||||
|
// by some number of blocks which will give us a square
|
||||||
|
// to teleport players on the edge of.
|
||||||
|
Location expandedBottomLeft = lowestLoc.clone();
|
||||||
|
Location expandedTopRight = highestLoc.clone();
|
||||||
|
|
||||||
|
// Move the corners to the same Y-Level
|
||||||
|
expandedTopRight.setY(lowestLoc.getY());
|
||||||
|
|
||||||
|
// Set the x of bottom left and top right to be left/right
|
||||||
|
// respectively...
|
||||||
|
expandedBottomLeft.setX(Math.min(lowestLoc.getX(), highestLoc.getX()) - TELEPORT_BORDER_DISTANCE);
|
||||||
|
expandedTopRight.setX(Math.max(lowestLoc.getX(), highestLoc.getX()) + TELEPORT_BORDER_DISTANCE);
|
||||||
|
|
||||||
|
// Set the z of bottom left and top right to be bottom/top
|
||||||
|
// respectively...
|
||||||
|
expandedBottomLeft.setZ(Math.min(lowestLoc.getZ(), highestLoc.getZ()) - TELEPORT_BORDER_DISTANCE);
|
||||||
|
expandedTopRight.setZ(Math.max(lowestLoc.getZ(), highestLoc.getZ()) + TELEPORT_BORDER_DISTANCE);
|
||||||
|
|
||||||
|
// Now that we have the two corners of the square, get a list with all
|
||||||
|
// the locations for the square's edge.
|
||||||
|
List<Location> 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;
|
spaceIndex += spacesBetween;
|
||||||
double oZ = Math.cos(lead) * 26;
|
|
||||||
|
|
||||||
Location loc = data.Spawn.clone().add(oX, 0, oZ);
|
if (spaceIndex > edgeLocations.size())
|
||||||
loc.setDirection(UtilAlg.getTrajectory(loc, data.Spawn));
|
{
|
||||||
|
spaceIndex = 0;
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user