Skip to content

Commit 51c8100

Browse files
Eliminate use of VThreads when utilizing Folia to permit usage of //undo and //redo
1 parent fb042e5 commit 51c8100

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/ChangeExchangeCoordinator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fastasyncworldedit.core.history.changeset;
22

3+
import com.fastasyncworldedit.core.util.FoliaSupport;
34
import com.sk89q.worldedit.history.change.Change;
45
import org.jetbrains.annotations.ApiStatus;
56

@@ -30,12 +31,18 @@ public Change[] take(Change[] consumed) {
3031
if (!this.started) {
3132
this.started = true;
3233
final int length = consumed.length;
33-
this.runner = UNDO_VIRTUAL_THREAD_BUILDER
34-
.start(() -> this.runnerTask.accept(this.exchanger, new Change[length]));
34+
if (FoliaSupport.isFolia()) {
35+
this.runner = new Thread(() -> this.runnerTask.accept(this.exchanger, new Change[length]), "FAWE undo");
36+
this.runner.setDaemon(true);
37+
this.runner.start();
38+
} else {
39+
this.runner = UNDO_VIRTUAL_THREAD_BUILDER
40+
.start(() -> this.runnerTask.accept(this.exchanger, new Change[length]));
41+
}
3542
}
3643
try {
37-
// Allow a reasonable timeout in case of weirdness
38-
return exchanger.exchange(consumed, 30, TimeUnit.SECONDS);
44+
long timeoutSeconds = FoliaSupport.isFolia() ? 60 : 30;
45+
return exchanger.exchange(consumed, timeoutSeconds, TimeUnit.SECONDS);
3946
} catch (InterruptedException | TimeoutException e) {
4047
this.runner.interrupt();
4148
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)