mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
Avoid loading islands unless necessary
This commit is contained in:
parent
801af3d592
commit
3d696e10d5
2
pom.xml
2
pom.xml
@ -88,7 +88,7 @@
|
|||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- 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.organization>bentobox-world</sonar.organization>
|
||||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||||
<server.jars>${project.basedir}/lib</server.jars>
|
<server.jars>${project.basedir}/lib</server.jars>
|
||||||
|
@ -442,7 +442,7 @@ public class IslandsManager {
|
|||||||
: Optional.empty();
|
: Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIslandAd(@NonNull Location location) {
|
public boolean isIslandAt(@NonNull Location location) {
|
||||||
return plugin.getIWM().inWorld(location) ? islandCache.isIslandAt(location) : false;
|
return plugin.getIWM().inWorld(location) ? islandCache.isIslandAt(location) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,9 @@ public class DefaultNewIslandLocationStrategy implements NewIslandLocationStrate
|
|||||||
*/
|
*/
|
||||||
protected Result isIsland(Location location) {
|
protected Result isIsland(Location location) {
|
||||||
// Quick check
|
// 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();
|
World world = location.getWorld();
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class IslandGrid {
|
|||||||
// Check if we know about this island already
|
// Check if we know about this island already
|
||||||
int minX = island.getMinX();
|
int minX = island.getMinX();
|
||||||
int minZ = island.getMinZ();
|
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)) {
|
if (grid.containsKey(minX)) {
|
||||||
TreeMap<Integer, IslandData> zEntry = grid.get(minX);
|
TreeMap<Integer, IslandData> zEntry = grid.get(minX);
|
||||||
if (zEntry.containsKey(minZ)) {
|
if (zEntry.containsKey(minZ)) {
|
||||||
@ -99,7 +99,7 @@ class IslandGrid {
|
|||||||
* Checks if an island is at this coordinate or not
|
* Checks if an island is at this coordinate or not
|
||||||
* @param x coord
|
* @param x coord
|
||||||
* @param z 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) {
|
public boolean isIslandAt(int x, int z) {
|
||||||
return getIslandStringAt(x, z) != null;
|
return getIslandStringAt(x, z) != null;
|
||||||
@ -124,8 +124,8 @@ class IslandGrid {
|
|||||||
return null; // No z-coordinate entry found, return null
|
return null; // No z-coordinate entry found, return null
|
||||||
}
|
}
|
||||||
// Check if the specified coordinates are within the island space
|
// Check if the specified coordinates are within the island space
|
||||||
if (x >= zEntry.getValue().minX() && x < zEntry.getValue().minX() + 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) {
|
&& z >= zEntry.getValue().minZ() && z < (zEntry.getValue().minZ() + zEntry.getValue().range() * 2)) {
|
||||||
return zEntry.getValue().id();
|
return zEntry.getValue().id();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -137,6 +137,7 @@ public class IslandCacheTest extends AbstractCommonSetup {
|
|||||||
when(island.getMemberSet()).thenReturn(members.build());
|
when(island.getMemberSet()).thenReturn(members.build());
|
||||||
when(island.getMinX()).thenReturn(-200);
|
when(island.getMinX()).thenReturn(-200);
|
||||||
when(island.getMinZ()).thenReturn(-200);
|
when(island.getMinZ()).thenReturn(-200);
|
||||||
|
when(island.getRange()).thenReturn(400);
|
||||||
|
|
||||||
// database must be mocked here
|
// database must be mocked here
|
||||||
db = mock(Database.class);
|
db = mock(Database.class);
|
||||||
@ -234,12 +235,10 @@ public class IslandCacheTest extends AbstractCommonSetup {
|
|||||||
|
|
||||||
Location location2 = mock(Location.class);
|
Location location2 = mock(Location.class);
|
||||||
when(location2.getWorld()).thenReturn(world);
|
when(location2.getWorld()).thenReturn(world);
|
||||||
when(location2.getBlockX()).thenReturn(10);
|
when(location2.getBlockX()).thenReturn(10000);
|
||||||
when(location2.getBlockY()).thenReturn(10);
|
when(location2.getBlockY()).thenReturn(100);
|
||||||
when(location2.getBlockZ()).thenReturn(10);
|
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));
|
assertNull(ic.getIslandAt(location2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user