mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +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
@@ -233,6 +233,7 @@ public class TpCommand extends CommandBase {
|
|||||||
(yaw != null ? yaw : player.getLocation().getYaw()),
|
(yaw != null ? yaw : player.getLocation().getYaw()),
|
||||||
(pitch != null ? pitch : player.getLocation().getPitch()),
|
(pitch != null ? pitch : player.getLocation().getPitch()),
|
||||||
serverId != null || HuskHomes.getSettings().doBungee() ? serverId : HuskHomes.getSettings().getServerID());
|
serverId != null || HuskHomes.getSettings().doBungee() ? serverId : HuskHomes.getSettings().getServerID());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
TeleportManager.teleportPlayer(player, teleportationPoint);
|
TeleportManager.teleportPlayer(player, teleportationPoint);
|
||||||
if (sender instanceof Player sendingPlayer) {
|
if (sender instanceof Player sendingPlayer) {
|
||||||
|
|||||||
@@ -46,12 +46,20 @@ public class TeleportManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Teleport a player to a location on the server or proxy server network
|
// Teleport a player to a location on the server or proxy server network
|
||||||
public static void teleportPlayer(Player player, TeleportationPoint point) {
|
public static void teleportPlayer(Player player, TeleportationPoint targetPoint) {
|
||||||
final TeleportationPoint destination = new TeleportationPoint(player.getLocation(),
|
final TeleportationPoint currentPosition = new TeleportationPoint(player.getLocation(),
|
||||||
HuskHomes.getSettings().getServerID());
|
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()) {
|
try (Connection connection = HuskHomes.getConnection()) {
|
||||||
DataManager.setPlayerLastPosition(player, destination, connection);
|
DataManager.setPlayerLastPosition(player, currentPosition, connection);
|
||||||
DataManager.setPlayerDestinationLocation(player, point, connection);
|
DataManager.setPlayerDestinationLocation(player, targetPoint, connection);
|
||||||
teleportPlayer(player);
|
teleportPlayer(player);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting a player.", e);
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting a player.", e);
|
||||||
@@ -108,7 +116,7 @@ public class TeleportManager {
|
|||||||
}
|
}
|
||||||
} catch (SQLException sqlException) {
|
} catch (SQLException sqlException) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting a player", 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");
|
MessageManager.sendMessage(player, "error_invalid_on_arrival");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class TeleportationPoint {
|
|||||||
if (world != null) {
|
if (world != null) {
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
} else {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a ma
|
|||||||
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
||||||
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
||||||
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
||||||
|
error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)'
|
||||||
home_command_description: 'Teleport to one of your homes'
|
home_command_description: 'Teleport to one of your homes'
|
||||||
sethome_command_description: 'Set a new home with given name'
|
sethome_command_description: 'Set a new home with given name'
|
||||||
delhome_command_description: 'Delete a home you previously set'
|
delhome_command_description: 'Delete a home you previously set'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a ma
|
|||||||
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
||||||
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
||||||
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
||||||
|
error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)'
|
||||||
home_command_description: 'Teleport to one of your homes'
|
home_command_description: 'Teleport to one of your homes'
|
||||||
sethome_command_description: 'Set a new home with given name'
|
sethome_command_description: 'Set a new home with given name'
|
||||||
delhome_command_description: 'Delete a home you previously set'
|
delhome_command_description: 'Delete a home you previously set'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ error_edit_home_maximum_public_homes: '[Błąd:](#ff3300) [Możesz maksymalnie u
|
|||||||
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
||||||
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
||||||
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
||||||
|
error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)'
|
||||||
home_command_description: 'Teleport to one of your homes'
|
home_command_description: 'Teleport to one of your homes'
|
||||||
sethome_command_description: 'Set a new home with given name'
|
sethome_command_description: 'Set a new home with given name'
|
||||||
delhome_command_description: 'Delete a home you previously set'
|
delhome_command_description: 'Delete a home you previously set'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a ma
|
|||||||
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
||||||
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
||||||
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
||||||
|
error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)'
|
||||||
home_command_description: 'Teleport to one of your homes'
|
home_command_description: 'Teleport to one of your homes'
|
||||||
sethome_command_description: 'Set a new home with given name'
|
sethome_command_description: 'Set a new home with given name'
|
||||||
delhome_command_description: 'Delete a home you previously set'
|
delhome_command_description: 'Delete a home you previously set'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a ma
|
|||||||
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
|
||||||
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)'
|
||||||
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)'
|
||||||
|
error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)'
|
||||||
home_command_description: 'Teleport to one of your homes'
|
home_command_description: 'Teleport to one of your homes'
|
||||||
sethome_command_description: 'Set a new home with given name'
|
sethome_command_description: 'Set a new home with given name'
|
||||||
delhome_command_description: 'Delete a home you previously set'
|
delhome_command_description: 'Delete a home you previously set'
|
||||||
|
|||||||
Reference in new issue
Block a user