Skip to content

Commit 162dea8

Browse files
committed
Add for 1.21.3
1 parent 5689622 commit 162dea8

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
1818
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
1919
import com.fastasyncworldedit.core.util.MathMan;
20+
import com.fastasyncworldedit.core.util.MemUtil;
2021
import com.fastasyncworldedit.core.util.NbtUtils;
2122
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
2223
import com.sk89q.worldedit.bukkit.BukkitAdapter;
@@ -211,7 +212,7 @@ public void setSkyLightingToGet(char[][] light, int minSectionPosition, int maxS
211212
try {
212213
fillLightNibble(light, LightLayer.SKY, minSectionPosition, maxSectionPosition);
213214
} catch (Throwable e) {
214-
LOGGER.error("Error setting lighting to get", e);
215+
LOGGER.error("Error setting sky lighting to get", e);
215216
}
216217
}
217218
}
@@ -432,7 +433,7 @@ public CompletableFuture<LevelChunk> ensureLoaded(ServerLevel nmsWorld, int chun
432433
}
433434

434435
@Override
435-
@SuppressWarnings("rawtypes")
436+
@SuppressWarnings({"rawtypes", "unchecked"})
436437
public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk> owner, IChunkSet set, Runnable finalizer) {
437438
if (!callLock.isHeldByCurrentThread()) {
438439
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
@@ -441,18 +442,34 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
441442
final ServerLevel nmsWorld = serverLevel;
442443
CompletableFuture<LevelChunk> nmsChunkFuture = ensureLoaded(nmsWorld, chunkX, chunkZ);
443444
LevelChunk chunk = nmsChunkFuture.getNow(null);
445+
if ((chunk == null && MemUtil.shouldBeginSlow()) || Settings.settings().QUEUE.ASYNC_CHUNK_LOAD_WRITE) {
446+
try {
447+
// "Artificially" slow FAWE down if memory low as performing the operation async can cause large amounts of
448+
// memory usage
449+
chunk = nmsChunkFuture.get();
450+
} catch (InterruptedException | ExecutionException e) {
451+
LOGGER.error("Could not get chunk at {},{} whilst low memory", chunkX, chunkZ, e);
452+
throw new FaweException(
453+
TextComponent.of("Could not get chunk at " + chunkX + "," + chunkZ + " whilst low memory: " + e.getMessage()));
454+
}
455+
}
444456
final int finalCopyKey = copyKey;
445457
// Run immediately if possible
446458
if (chunk != null) {
447459
return tryWrappedInternalCall(set, finalizer, finalCopyKey, chunk, nmsWorld);
448460
}
461+
// Submit via the STQE as that will help handle excessive queuing by waiting for the submission count to fall below the
462+
// target size
449463
nmsChunkFuture.thenApply(nmsChunk -> owner.submitTaskUnchecked(() -> (T) tryWrappedInternalCall(
450464
set,
451465
finalizer,
452466
finalCopyKey,
453467
nmsChunk,
454468
nmsWorld
455469
)));
470+
// If we have re-submitted, return a completed future to prevent potential deadlocks where a future reliant on the
471+
// above submission is halting the BlockingExecutor, and preventing the above task from actually running. The futures
472+
// submitted above will still be added to the STQE submissions.
456473
return (T) (Future) CompletableFuture.completedFuture(null);
457474
}
458475

worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightPlatformAdapter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import net.minecraft.world.level.chunk.status.ChunkStatus;
5757
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
5858
import org.apache.logging.log4j.Logger;
59-
import org.bukkit.Bukkit;
6059
import org.bukkit.craftbukkit.CraftChunk;
6160

6261
import javax.annotation.Nonnull;
@@ -79,8 +78,6 @@
7978
import java.util.concurrent.CompletableFuture;
8079
import java.util.concurrent.ExecutionException;
8180
import java.util.concurrent.Semaphore;
82-
import java.util.concurrent.TimeUnit;
83-
import java.util.concurrent.TimeoutException;
8481
import java.util.function.IntFunction;
8582

8683
import static java.lang.invoke.MethodType.methodType;

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
1818
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
1919
import com.fastasyncworldedit.core.util.MathMan;
20+
import com.fastasyncworldedit.core.util.MemUtil;
2021
import com.fastasyncworldedit.core.util.NbtUtils;
2122
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
2223
import com.sk89q.worldedit.bukkit.BukkitAdapter;
@@ -432,7 +433,7 @@ public CompletableFuture<LevelChunk> ensureLoaded(ServerLevel nmsWorld, int chun
432433
}
433434

434435
@Override
435-
@SuppressWarnings("rawtypes")
436+
@SuppressWarnings({"rawtypes", "unchecked"})
436437
public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk> owner, IChunkSet set, Runnable finalizer) {
437438
if (!callLock.isHeldByCurrentThread()) {
438439
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
@@ -441,18 +442,34 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
441442
final ServerLevel nmsWorld = serverLevel;
442443
CompletableFuture<LevelChunk> nmsChunkFuture = ensureLoaded(nmsWorld, chunkX, chunkZ);
443444
LevelChunk chunk = nmsChunkFuture.getNow(null);
445+
if ((chunk == null && MemUtil.shouldBeginSlow()) || Settings.settings().QUEUE.ASYNC_CHUNK_LOAD_WRITE) {
446+
try {
447+
// "Artificially" slow FAWE down if memory low as performing the operation async can cause large amounts of
448+
// memory usage
449+
chunk = nmsChunkFuture.get();
450+
} catch (InterruptedException | ExecutionException e) {
451+
LOGGER.error("Could not get chunk at {},{} whilst low memory", chunkX, chunkZ, e);
452+
throw new FaweException(
453+
TextComponent.of("Could not get chunk at " + chunkX + "," + chunkZ + " whilst low memory: " + e.getMessage()));
454+
}
455+
}
444456
final int finalCopyKey = copyKey;
445457
// Run immediately if possible
446458
if (chunk != null) {
447459
return tryWrappedInternalCall(set, finalizer, finalCopyKey, chunk, nmsWorld);
448460
}
461+
// Submit via the STQE as that will help handle excessive queuing by waiting for the submission count to fall below the
462+
// target size
449463
nmsChunkFuture.thenApply(nmsChunk -> owner.submitTaskUnchecked(() -> (T) tryWrappedInternalCall(
450464
set,
451465
finalizer,
452466
finalCopyKey,
453467
nmsChunk,
454468
nmsWorld
455469
)));
470+
// If we have re-submitted, return a completed future to prevent potential deadlocks where a future reliant on the
471+
// above submission is halting the BlockingExecutor, and preventing the above task from actually running. The futures
472+
// submitted above will still be added to the STQE submissions.
456473
return (T) (Future) CompletableFuture.completedFuture(null);
457474
}
458475

worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightPlatformAdapter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import net.minecraft.world.level.chunk.status.ChunkStatus;
5656
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
5757
import org.apache.logging.log4j.Logger;
58-
import org.bukkit.Bukkit;
5958
import org.bukkit.craftbukkit.CraftChunk;
6059

6160
import javax.annotation.Nonnull;
@@ -78,8 +77,6 @@
7877
import java.util.concurrent.CompletableFuture;
7978
import java.util.concurrent.ExecutionException;
8079
import java.util.concurrent.Semaphore;
81-
import java.util.concurrent.TimeUnit;
82-
import java.util.concurrent.TimeoutException;
8380
import java.util.function.IntFunction;
8481

8582
import static java.lang.invoke.MethodType.methodType;

0 commit comments

Comments
 (0)