package wtf.beatrice.limbomanager.objects; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import wtf.beatrice.limbomanager.Cache; import java.util.ArrayList; import java.util.List; public class LocationCheckRunnable implements Runnable { public BukkitTask task; List playersToCheck = new ArrayList<>(); private final static int distanceMax = 100; // we give players a distanceMax block range to move in. // if they go out, we teleport them back to their island's spawnpoint. @Override public void run() { // if we checked all players, refill the list and skip the check for this time (in case server is empty). if(playersToCheck.isEmpty()) { playersToCheck.addAll(Bukkit.getServer().getOnlinePlayers()); return; } Player player = playersToCheck.get(0); Location playerLocation = player.getLocation(); playersToCheck.remove(player); Coordinates playerIslandCoordinates = Cache.playerIslands.get(player.getName()); int distanceX = Math.abs(playerLocation.getBlockX() - playerIslandCoordinates.getX()); int distanceZ = Math.abs(playerLocation.getBlockZ() - playerIslandCoordinates.getZ()); if(distanceX > distanceMax || distanceZ > distanceMax) { Cache.teleportToOwnIsland(player); player.sendMessage("Out of island limits"); } } } // 1500 1000 // 1000 1000 // 700 1000