Skip to content

Commit 3d696e1

Browse files
committed
Avoid loading islands unless necessary
1 parent 801af3d commit 3d696e1

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

pom.xml

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

src/main/java/world/bentobox/bentobox/managers/IslandsManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public Optional<Island> getIslandAt(@NonNull Location location) {
442442
: Optional.empty();
443443
}
444444

445-
public boolean isIslandAd(@NonNull Location location) {
445+
public boolean isIslandAt(@NonNull Location location) {
446446
return plugin.getIWM().inWorld(location) ? islandCache.isIslandAt(location) : false;
447447
}
448448

src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public Location getNextLocation(World world) {
7474
*/
7575
protected Result isIsland(Location location) {
7676
// Quick check
77-
if (plugin.getIslands().getIslandAt(location).isPresent()) return Result.ISLAND_FOUND;
77+
if (plugin.getIslands().isIslandAt(location)) {
78+
return Result.ISLAND_FOUND;
79+
}
7880

7981
World world = location.getWorld();
8082

src/main/java/world/bentobox/bentobox/managers/island/IslandGrid.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean addToGrid(Island island) {
3737
// Check if we know about this island already
3838
int minX = island.getMinX();
3939
int minZ = island.getMinZ();
40-
IslandData islandData = new IslandData(island.getUniqueId(), minZ, minZ, island.getRange());
40+
IslandData islandData = new IslandData(island.getUniqueId(), minX, minZ, island.getRange());
4141
if (grid.containsKey(minX)) {
4242
TreeMap<Integer, IslandData> zEntry = grid.get(minX);
4343
if (zEntry.containsKey(minZ)) {
@@ -99,7 +99,7 @@ public Island getIslandAt(int x, int z) {
9999
* Checks if an island is at this coordinate or not
100100
* @param x coord
101101
* @param z coord
102-
* @return true if there is an island registered in the grid
102+
* @return true if there is an island registered here in the grid
103103
*/
104104
public boolean isIslandAt(int x, int z) {
105105
return getIslandStringAt(x, z) != null;
@@ -124,8 +124,8 @@ public boolean isIslandAt(int x, int z) {
124124
return null; // No z-coordinate entry found, return null
125125
}
126126
// Check if the specified coordinates are within the island space
127-
if (x >= zEntry.getValue().minX() && x < zEntry.getValue().minX() + zEntry.getValue().range() * 2
128-
&& z >= zEntry.getValue().minZ() && z < zEntry.getValue().minZ() + zEntry.getValue().range() * 2) {
127+
if (x >= zEntry.getValue().minX() && x < (zEntry.getValue().minX() + zEntry.getValue().range() * 2)
128+
&& z >= zEntry.getValue().minZ() && z < (zEntry.getValue().minZ() + zEntry.getValue().range() * 2)) {
129129
return zEntry.getValue().id();
130130
}
131131
return null;

src/test/java/world/bentobox/bentobox/managers/island/IslandCacheTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void setUp() throws Exception {
137137
when(island.getMemberSet()).thenReturn(members.build());
138138
when(island.getMinX()).thenReturn(-200);
139139
when(island.getMinZ()).thenReturn(-200);
140+
when(island.getRange()).thenReturn(400);
140141

141142
// database must be mocked here
142143
db = mock(Database.class);
@@ -234,12 +235,10 @@ public void testGetIslandAtLocation() throws InstantiationException, IllegalAcce
234235

235236
Location location2 = mock(Location.class);
236237
when(location2.getWorld()).thenReturn(world);
237-
when(location2.getBlockX()).thenReturn(10);
238-
when(location2.getBlockY()).thenReturn(10);
239-
when(location2.getBlockZ()).thenReturn(10);
238+
when(location2.getBlockX()).thenReturn(10000);
239+
when(location2.getBlockY()).thenReturn(100);
240+
when(location2.getBlockZ()).thenReturn(10000);
240241

241-
assertEquals(island, ic.getIslandAt(location2));
242-
when(island.inIslandSpace(any(Integer.class), any(Integer.class))).thenReturn(false);
243242
assertNull(ic.getIslandAt(location2));
244243
}
245244

0 commit comments

Comments
 (0)