From d30e335f577a713f6a5d976a397ac4fdd9f0c30e Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:17:18 +0100 Subject: [PATCH] Disallow custom spawns that are out of bounds --- .../totalfreedommod/MovementValidator.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 1dcbbf61..7b70158b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.spigotmc.event.player.PlayerSpawnLocationEvent; public class MovementValidator extends FreedomService { @@ -74,4 +75,23 @@ public class MovementValidator extends FreedomService PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn } } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerSpawn(PlayerSpawnLocationEvent event) + { + final Location playerSpawn = event.getSpawnLocation(); + final Location worldSpawn = event.getPlayer().getWorld().getSpawnLocation(); + + // If the player's spawn is equal to the world's spawn, there is no need to check. + // This will also prevent any possible feedback loops pertaining to setting an out of bounds world spawn to the same world spawn. + if (playerSpawn == worldSpawn) + { + return; + } + + if (isOutOfBounds(worldSpawn)) + { + event.setSpawnLocation(worldSpawn); + } + } } \ No newline at end of file