diff --git a/src/main/java/wtf/beatrice/limbomanager/LimboManager.java b/src/main/java/wtf/beatrice/limbomanager/LimboManager.java index 13028b7..b04d219 100644 --- a/src/main/java/wtf/beatrice/limbomanager/LimboManager.java +++ b/src/main/java/wtf/beatrice/limbomanager/LimboManager.java @@ -54,6 +54,7 @@ public class LimboManager extends JavaPlugin { // start location check runnable Cache.locationCheckRunnable = new LocationCheckRunnable(); + Cache.locationCheckRunnable.setDistanceMax(configuration.getInt("sizing.allowed-range")); Cache.locationCheckRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, Cache.locationCheckRunnable, 10L, 5L); } diff --git a/src/main/java/wtf/beatrice/limbomanager/objects/LocationCheckRunnable.java b/src/main/java/wtf/beatrice/limbomanager/objects/LocationCheckRunnable.java index b0dded7..b878350 100644 --- a/src/main/java/wtf/beatrice/limbomanager/objects/LocationCheckRunnable.java +++ b/src/main/java/wtf/beatrice/limbomanager/objects/LocationCheckRunnable.java @@ -16,7 +16,7 @@ public class LocationCheckRunnable implements Runnable public BukkitTask task; List playersToCheck = new ArrayList<>(); - private final static int distanceMax = 100; + private int distanceMax = 100; //just a default value // we give players a distanceMax block range to move in. @@ -44,23 +44,34 @@ public class LocationCheckRunnable implements Runnable Location playerLocation = player.getLocation(); - Coordinates playerIslandCoordinates = Cache.playerIslands.get(player.getName()); + int spawnOffsetX = Cache.getConfiguration().getInt("island.spawn-offset.x"); + int spawnOffsetZ = Cache.getConfiguration().getInt("island.spawn-offset.z"); - int distanceX = Math.abs(playerLocation.getBlockX() - playerIslandCoordinates.getX()); - int distanceZ = Math.abs(playerLocation.getBlockZ() - playerIslandCoordinates.getZ()); + // we are copying the object because otherwise we'd be directly editing the reference in the hashmap + // and causing a lot of trouble by moving the spawnpoint itself. + Coordinates islandSpawnCoordinates = new Coordinates(Cache.playerIslands.get(player.getName())); + + islandSpawnCoordinates.setX(islandSpawnCoordinates.getX() + spawnOffsetX); + islandSpawnCoordinates.setZ(islandSpawnCoordinates.getZ() + spawnOffsetZ); + + + // calculate absolute distance from spawnpoint + int distanceX = Math.abs(playerLocation.getBlockX() - islandSpawnCoordinates.getX()); + int distanceZ = Math.abs(playerLocation.getBlockZ() - islandSpawnCoordinates.getZ()); + + // check if player is inside bounds if(distanceX > distanceMax || distanceZ > distanceMax) { LocationUtils.teleportToOwnIsland(player); - player.sendMessage("Out of island limits"); + player.sendMessage("Out of bounds"); + + } + } - + public void setDistanceMax(int distanceMax) + { + this.distanceMax = distanceMax; } } - - - -// 1500 1000 -// 1000 1000 -// 700 1000 \ No newline at end of file