mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-12-22 17:18:44 +01:00
Update IslandLevelCalculator.java (#314)
Fix for occasional errors likely due to the use of the remove() method within a lambda expression inside the thenAccept method. This lambda expression is executed asynchronously, which means that the iterator may not be in a consistent state when remove() is called.
This commit is contained in:
parent
5dee0d2426
commit
0bb6eacaf7
@ -638,27 +638,37 @@ public class IslandLevelCalculator {
|
||||
}
|
||||
|
||||
private void handleStackedBlocks() {
|
||||
// Deal with any stacked blocks
|
||||
Iterator<Location> it = stackedBlocks.iterator();
|
||||
while (it.hasNext()) {
|
||||
Location v = it.next();
|
||||
Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||
Block stackedBlock = v.getBlock();
|
||||
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
||||
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
||||
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
||||
for (int _x = 0; _x < barrelAmt; _x++) {
|
||||
checkBlock(barrel.getType(), belowSeaLevel);
|
||||
}
|
||||
} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
|
||||
int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
|
||||
for (int _x = 0; _x < spawnerAmt; _x++) {
|
||||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
||||
}
|
||||
}
|
||||
it.remove();
|
||||
});
|
||||
}
|
||||
// Deal with any stacked blocks
|
||||
List<Location> toRemove = new ArrayList<>();
|
||||
Iterator<Location> it = stackedBlocks.iterator();
|
||||
while (it.hasNext()) {
|
||||
Location v = it.next();
|
||||
Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||
Block stackedBlock = v.getBlock();
|
||||
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
||||
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
||||
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
||||
for (int _x = 0; _x < barrelAmt; _x++) {
|
||||
checkBlock(barrel.getType(), belowSeaLevel);
|
||||
}
|
||||
} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
|
||||
int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
|
||||
for (int _x = 0; _x < spawnerAmt; _x++) {
|
||||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
||||
}
|
||||
}
|
||||
synchronized (toRemove) {
|
||||
toRemove.add(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Wait for all asynchronous tasks to complete before removing elements
|
||||
// Remove the elements collected in toRemove
|
||||
synchronized (toRemove) {
|
||||
stackedBlocks.removeAll(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user