Disallow custom spawns that are out of bounds

This commit is contained in:
Allink 2023-06-17 20:17:18 +01:00
parent cca95dc3f1
commit d30e335f57
No known key found for this signature in database
1 changed files with 20 additions and 0 deletions

View File

@ -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);
}
}
}