Avoid loading islands unless necessary

This commit is contained in:
tastybento 2024-10-20 20:32:49 -07:00
parent 801af3d592
commit 3d696e10d5
5 changed files with 13 additions and 12 deletions

View File

@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.6.0</build.version>
<build.version>2.7.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>

View File

@ -442,7 +442,7 @@ public class IslandsManager {
: Optional.empty();
}
public boolean isIslandAd(@NonNull Location location) {
public boolean isIslandAt(@NonNull Location location) {
return plugin.getIWM().inWorld(location) ? islandCache.isIslandAt(location) : false;
}

View File

@ -74,7 +74,9 @@ public class DefaultNewIslandLocationStrategy implements NewIslandLocationStrate
*/
protected Result isIsland(Location location) {
// Quick check
if (plugin.getIslands().getIslandAt(location).isPresent()) return Result.ISLAND_FOUND;
if (plugin.getIslands().isIslandAt(location)) {
return Result.ISLAND_FOUND;
}
World world = location.getWorld();

View File

@ -37,7 +37,7 @@ class IslandGrid {
// Check if we know about this island already
int minX = island.getMinX();
int minZ = island.getMinZ();
IslandData islandData = new IslandData(island.getUniqueId(), minZ, minZ, island.getRange());
IslandData islandData = new IslandData(island.getUniqueId(), minX, minZ, island.getRange());
if (grid.containsKey(minX)) {
TreeMap<Integer, IslandData> zEntry = grid.get(minX);
if (zEntry.containsKey(minZ)) {
@ -99,7 +99,7 @@ class IslandGrid {
* Checks if an island is at this coordinate or not
* @param x coord
* @param z coord
* @return true if there is an island registered in the grid
* @return true if there is an island registered here in the grid
*/
public boolean isIslandAt(int x, int z) {
return getIslandStringAt(x, z) != null;
@ -124,8 +124,8 @@ class IslandGrid {
return null; // No z-coordinate entry found, return null
}
// Check if the specified coordinates are within the island space
if (x >= zEntry.getValue().minX() && x < zEntry.getValue().minX() + zEntry.getValue().range() * 2
&& z >= zEntry.getValue().minZ() && z < zEntry.getValue().minZ() + zEntry.getValue().range() * 2) {
if (x >= zEntry.getValue().minX() && x < (zEntry.getValue().minX() + zEntry.getValue().range() * 2)
&& z >= zEntry.getValue().minZ() && z < (zEntry.getValue().minZ() + zEntry.getValue().range() * 2)) {
return zEntry.getValue().id();
}
return null;

View File

@ -137,6 +137,7 @@ public class IslandCacheTest extends AbstractCommonSetup {
when(island.getMemberSet()).thenReturn(members.build());
when(island.getMinX()).thenReturn(-200);
when(island.getMinZ()).thenReturn(-200);
when(island.getRange()).thenReturn(400);
// database must be mocked here
db = mock(Database.class);
@ -234,12 +235,10 @@ public class IslandCacheTest extends AbstractCommonSetup {
Location location2 = mock(Location.class);
when(location2.getWorld()).thenReturn(world);
when(location2.getBlockX()).thenReturn(10);
when(location2.getBlockY()).thenReturn(10);
when(location2.getBlockZ()).thenReturn(10);
when(location2.getBlockX()).thenReturn(10000);
when(location2.getBlockY()).thenReturn(100);
when(location2.getBlockZ()).thenReturn(10000);
assertEquals(island, ic.getIslandAt(location2));
when(island.inIslandSpace(any(Integer.class), any(Integer.class))).thenReturn(false);
assertNull(ic.getIslandAt(location2));
}