|
|
|
@ -16,7 +16,7 @@ public class LocationCheckRunnable implements Runnable
|
|
|
|
|
public BukkitTask task;
|
|
|
|
|
|
|
|
|
|
List<Player> 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
|