mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-01 00:10:40 +01:00
Fixes for Island cache issues
Fix the size check and the new island creation.
This commit is contained in:
parent
01dcd6ecc6
commit
250c7950f9
@ -1262,7 +1262,7 @@ public class IslandsManager {
|
||||
} else {
|
||||
// Fix island center if it is off
|
||||
fixIslandCenter(island);
|
||||
islandCache.addIsland(island);
|
||||
islandCache.addIsland(island, true);
|
||||
|
||||
if (island.isSpawn()) {
|
||||
// Success, set spawn if this is the spawn island.
|
||||
|
@ -97,17 +97,29 @@ public class IslandCache {
|
||||
|
||||
/**
|
||||
* Adds an island to the grid, used for new islands
|
||||
* Caches island.
|
||||
*
|
||||
* @param island island to add, not null
|
||||
* @return true if successfully added, false if not
|
||||
*/
|
||||
public boolean addIsland(@NonNull Island island) {
|
||||
return addIsland(island, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an island to the grid, used for new islands
|
||||
*
|
||||
* @param island island to add, not null
|
||||
* @param noCache - if true, island will not be cached
|
||||
* @return true if successfully added, false if not
|
||||
*/
|
||||
public boolean addIsland(@NonNull Island island, boolean noCache) {
|
||||
if (island.getCenter() == null || island.getWorld() == null) {
|
||||
return false;
|
||||
}
|
||||
if (addToGrid(island)) {
|
||||
// Insert a null into the map as a placeholder for cache
|
||||
islandsById.put(island.getUniqueId().intern(), null);
|
||||
islandsById.put(island.getUniqueId().intern(), noCache ? null : island);
|
||||
// Only add islands to this map if they are owned
|
||||
if (island.isOwned()) {
|
||||
islandsByUUID.computeIfAbsent(island.getOwner(), k -> new HashSet<>()).add(island.getUniqueId());
|
||||
@ -402,7 +414,8 @@ public class IslandCache {
|
||||
* @return the number of islands
|
||||
*/
|
||||
public long size(World world) {
|
||||
return this.islandsById.values().stream().map(Island::getWorld).filter(world::equals).count();
|
||||
// Get from grids because this is where we have islands by world
|
||||
return this.grids.containsKey(world) ? this.grids.get(world).getSize() : 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,4 +100,15 @@ class IslandGrid {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of islands stored in the grid
|
||||
*/
|
||||
public long getSize() {
|
||||
long count = 0;
|
||||
for (TreeMap<Integer, String> innerMap : grid.values()) {
|
||||
count += innerMap.size();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user