Skip to content

Commit d3f8cc0

Browse files
authored
Fix missed synchronization change in 1.21.9 adapter (#3352)
1 parent 0009970 commit d3f8cc0

File tree

1 file changed

+21
-11
lines changed
  • worldedit-bukkit/adapters/adapter-1_21_9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_9

1 file changed

+21
-11
lines changed

worldedit-bukkit/adapters/adapter-1_21_9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_9/PaperweightGetBlocks.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,19 +1002,29 @@ public boolean hasNonEmptySection(int layer) {
10021002

10031003
@Override
10041004
@SuppressWarnings("unchecked")
1005-
public synchronized boolean trim(boolean aggressive) {
1006-
skyLight = new DataLayer[getSectionCount()];
1007-
blockLight = new DataLayer[getSectionCount()];
1005+
public boolean trim(boolean aggressive) {
1006+
synchronized (this) {
1007+
if (sections == null && (!aggressive || levelChunk == null)) {
1008+
skyLight = new DataLayer[getSectionCount()];
1009+
blockLight = new DataLayer[getSectionCount()];
1010+
return !aggressive || super.trim(true);
1011+
}
1012+
}
10081013
if (aggressive) {
10091014
sectionLock.writeLock().lock();
1010-
sections = null;
1011-
levelChunk = null;
1012-
sectionLock.writeLock().unlock();
1013-
return super.trim(true);
1014-
} else if (sections == null) {
1015-
// don't bother trimming if there are no sections stored.
1016-
return true;
1017-
} else {
1015+
try {
1016+
synchronized (this) {
1017+
skyLight = new DataLayer[getSectionCount()];
1018+
blockLight = new DataLayer[getSectionCount()];
1019+
sections = null;
1020+
levelChunk = null;
1021+
return super.trim(true);
1022+
}
1023+
} finally {
1024+
sectionLock.writeLock().unlock();
1025+
}
1026+
}
1027+
synchronized (this) {
10181028
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
10191029
int layer = i - getMinSectionPosition();
10201030
if (!hasSection(i) || super.blocks[layer] == null) {

0 commit comments

Comments
 (0)