mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Add additional safety checks to prevent players teleporting out of bounds, fix wrongly caught IllegalArgumentException preventing the invalid on arrival error from showing, Fix #133
This commit is contained in:
1 parent
a768171e32
commit
010040cf51
8 files changed
+20
-6
No files matched your search
@@ -46,12 +46,20 @@ public class TeleportManager {
|
||||
}
|
||||
|
||||
// Teleport a player to a location on the server or proxy server network
|
||||
public static void teleportPlayer(Player player, TeleportationPoint point) {
|
||||
final TeleportationPoint destination = new TeleportationPoint(player.getLocation(),
|
||||
public static void teleportPlayer(Player player, TeleportationPoint targetPoint) {
|
||||
final TeleportationPoint currentPosition = new TeleportationPoint(player.getLocation(),
|
||||
HuskHomes.getSettings().getServerID());
|
||||
|
||||
// Safety checks
|
||||
if (Math.abs(targetPoint.getX()) > 30000000 || Math.abs(targetPoint.getZ()) > 30000000 || Math.abs(targetPoint.getY()) > 30000000) {
|
||||
MessageManager.sendMessage(player, "error_invalid_coordinates");
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute teleport
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
DataManager.setPlayerLastPosition(player, destination, connection);
|
||||
DataManager.setPlayerDestinationLocation(player, point, connection);
|
||||
DataManager.setPlayerLastPosition(player, currentPosition, connection);
|
||||
DataManager.setPlayerDestinationLocation(player, targetPoint, connection);
|
||||
teleportPlayer(player);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting a player.", e);
|
||||
@@ -108,7 +116,7 @@ public class TeleportManager {
|
||||
}
|
||||
} catch (SQLException sqlException) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting a player", sqlException);
|
||||
} catch (IllegalArgumentException illegalArgumentException) {
|
||||
} catch (IllegalStateException illegalStateException) {
|
||||
MessageManager.sendMessage(player, "error_invalid_on_arrival");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ public class TeleportationPoint {
|
||||
if (world != null) {
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
throw new IllegalStateException("The world \"" + worldName + "\" could not be found on the server; could not return location");
|
||||
throw new IllegalStateException(worldName + " is not a valid world on the server; failed to return location");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user