Implement island max walking range from spawnpoint
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
fcbd6c5d01
commit
2866573d0d
@ -54,6 +54,7 @@ public class LimboManager extends JavaPlugin {
|
|||||||
|
|
||||||
// start location check runnable
|
// start location check runnable
|
||||||
Cache.locationCheckRunnable = new LocationCheckRunnable();
|
Cache.locationCheckRunnable = new LocationCheckRunnable();
|
||||||
|
Cache.locationCheckRunnable.setDistanceMax(configuration.getInt("sizing.allowed-range"));
|
||||||
Cache.locationCheckRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, Cache.locationCheckRunnable, 10L, 5L);
|
Cache.locationCheckRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, Cache.locationCheckRunnable, 10L, 5L);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class LocationCheckRunnable implements Runnable
|
|||||||
public BukkitTask task;
|
public BukkitTask task;
|
||||||
|
|
||||||
List<Player> playersToCheck = new ArrayList<>();
|
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.
|
// we give players a distanceMax block range to move in.
|
||||||
@ -44,23 +44,34 @@ public class LocationCheckRunnable implements Runnable
|
|||||||
|
|
||||||
Location playerLocation = player.getLocation();
|
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)
|
if(distanceX > distanceMax || distanceZ > distanceMax)
|
||||||
{
|
{
|
||||||
LocationUtils.teleportToOwnIsland(player);
|
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
|
|
Loading…
Reference in New Issue
Block a user