mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2025-02-19 14:01:24 +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
@ -639,6 +639,7 @@ public class IslandLevelCalculator {
|
|||||||
|
|
||||||
private void handleStackedBlocks() {
|
private void handleStackedBlocks() {
|
||||||
// Deal with any stacked blocks
|
// Deal with any stacked blocks
|
||||||
|
List<Location> toRemove = new ArrayList<>();
|
||||||
Iterator<Location> it = stackedBlocks.iterator();
|
Iterator<Location> it = stackedBlocks.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Location v = it.next();
|
Location v = it.next();
|
||||||
@ -657,8 +658,17 @@ public class IslandLevelCalculator {
|
|||||||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it.remove();
|
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