mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2025-02-16 12:31:22 +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() {
|
private void handleStackedBlocks() {
|
||||||
// Deal with any stacked blocks
|
// Deal with any stacked blocks
|
||||||
Iterator<Location> it = stackedBlocks.iterator();
|
List<Location> toRemove = new ArrayList<>();
|
||||||
while (it.hasNext()) {
|
Iterator<Location> it = stackedBlocks.iterator();
|
||||||
Location v = it.next();
|
while (it.hasNext()) {
|
||||||
Util.getChunkAtAsync(v).thenAccept(c -> {
|
Location v = it.next();
|
||||||
Block stackedBlock = v.getBlock();
|
Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||||
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
Block stackedBlock = v.getBlock();
|
||||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
||||||
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
||||||
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
||||||
for (int _x = 0; _x < barrelAmt; _x++) {
|
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
||||||
checkBlock(barrel.getType(), belowSeaLevel);
|
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());
|
} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
|
||||||
for (int _x = 0; _x < spawnerAmt; _x++) {
|
int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
|
||||||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
for (int _x = 0; _x < spawnerAmt; _x++) {
|
||||||
}
|
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