Skip to content

Commit

Permalink
Avoid loading islands unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Oct 21, 2024
1 parent 801af3d commit 3d696e1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public Optional<Island> getIslandAt(@NonNull Location location) {
: Optional.empty();
}

public boolean isIslandAd(@NonNull Location location) {
public boolean isIslandAt(@NonNull Location location) {
return plugin.getIWM().inWorld(location) ? islandCache.isIslandAt(location) : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public Location getNextLocation(World world) {
*/
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean addToGrid(Island island) {
// 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)) {
Expand Down Expand Up @@ -99,7 +99,7 @@ public Island getIslandAt(int x, int z) {
* 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;
Expand All @@ -124,8 +124,8 @@ public boolean isIslandAt(int x, int z) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void setUp() throws Exception {
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);
Expand Down Expand Up @@ -234,12 +235,10 @@ public void testGetIslandAtLocation() throws InstantiationException, IllegalAcce

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

Expand Down

0 comments on commit 3d696e1

Please sign in to comment.