Implement island max walking range from spawnpoint
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2022-11-12 01:44:07 +01:00
parent fcbd6c5d01
commit 2866573d0d
2 changed files with 24 additions and 12 deletions

View File

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

View File

@ -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