Implement island distance config option
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-11-12 01:50:27 +01:00
parent 2866573d0d
commit 8e299009a4
4 changed files with 12 additions and 12 deletions

View File

@ -10,6 +10,9 @@ public class Cache
{
public static final Coordinates baseCoords = new Coordinates(1000, 1000);
public static int islandsDistance = 500;
public static int islandWalkingRange = 100;
private static YamlConfiguration configuration;
public static final HashMap<String, Coordinates> playerIslands = new HashMap<>();

View File

@ -52,9 +52,12 @@ public class LimboManager extends JavaPlugin {
throw new RuntimeException(e);
}
// cache some config variables
Cache.islandWalkingRange = configuration.getInt("sizing.allowed-range");
Cache.islandsDistance = configuration.getInt("sizing.island-distance");
// 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

@ -96,7 +96,7 @@ public class PlayerTeleporter implements Listener
/*
how are islands laid out?
we start from (1000, 1000) and we put islands at 500 blocks distance up to 10000. then we move to a new row.
we start from (1000, 1000) and we put islands at <Cache.islandsDistance> blocks distance up to 10000. then we move to a new row.
*/
Coordinates islandCoords = new Coordinates(Cache.baseCoords);
@ -107,13 +107,13 @@ public class PlayerTeleporter implements Listener
if(!islandCoords.equals(currentCoords)) break;
// else, if they are the same,
// we have to either increase X or move to a new row, in case it's over 10000.
// we have to either increase X or move to a new row and reset X, in case it's over 10000.
if(islandCoords.getX() >= 10000) // if we need to create a new row
{
islandCoords.setX(1000);
islandCoords.setZ(islandCoords.getZ() + 500);
islandCoords.setZ(islandCoords.getZ() + Cache.islandsDistance);
} else { // if we just need to increase the column
islandCoords.setX(islandCoords.getX() + 500);
islandCoords.setX(islandCoords.getX() + Cache.islandsDistance);
}
}

View File

@ -16,7 +16,6 @@ public class LocationCheckRunnable implements Runnable
public BukkitTask task;
List<Player> playersToCheck = new ArrayList<>();
private int distanceMax = 100; //just a default value
// we give players a distanceMax block range to move in.
@ -61,7 +60,7 @@ public class LocationCheckRunnable implements Runnable
int distanceZ = Math.abs(playerLocation.getBlockZ() - islandSpawnCoordinates.getZ());
// check if player is inside bounds
if(distanceX > distanceMax || distanceZ > distanceMax)
if(distanceX > Cache.islandWalkingRange || distanceZ > Cache.islandWalkingRange)
{
LocationUtils.teleportToOwnIsland(player);
player.sendMessage("Out of bounds");
@ -69,9 +68,4 @@ public class LocationCheckRunnable implements Runnable
}
}
public void setDistanceMax(int distanceMax)
{
this.distanceMax = distanceMax;
}
}