3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-20 09:50:06 +01:00

Use new method to check of is running on "main thread"

Dieser Commit ist enthalten in:
Phillipp Glanz 2023-04-03 12:21:14 +02:00
Ursprung 5653712d24
Commit 9d09322837
18 geänderte Dateien mit 35 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -95,7 +95,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
@ -266,7 +266,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -204,7 +204,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
@ -219,7 +219,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);

Datei anzeigen

@ -95,7 +95,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
@ -266,7 +266,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -220,7 +220,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
@ -235,7 +235,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);

Datei anzeigen

@ -95,7 +95,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
@ -266,7 +266,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -257,7 +257,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
@ -272,7 +272,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);

Datei anzeigen

@ -95,7 +95,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = (int) RegionizedServer.getGlobalTickData().getCurrentTick();
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
@ -266,7 +266,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -261,7 +261,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
@ -274,7 +274,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);

Datei anzeigen

@ -160,7 +160,7 @@ public class FaweDelegateSchematicHandler {
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
com.fastasyncworldedit.core.util.TaskManager.taskManager().async(r);
} else {
r.run();

Datei anzeigen

@ -365,7 +365,7 @@ public class BukkitWorld extends AbstractWorld {
//FAWE start
int X = pt.getBlockX() >> 4;
int Z = pt.getBlockZ() >> 4;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
world.getChunkAt(X, Z);
} else if (PaperLib.isPaper()) {
PaperLib.getChunkAtAsync(world, X, Z, true);

Datei anzeigen

@ -156,7 +156,7 @@ public enum FaweCache implements Trimable {
*/
public <V> LongFunction<V> createMainThreadSafeCache(Supplier<V> withInitial) {
return new LongFunction<>() {
private final LoadingCache<Long, V> loadingCache = Fawe.isMainThread() ? null : FaweCache.INSTANCE.createCache(
private final LoadingCache<Long, V> loadingCache = Fawe.isTickThread() ? null : FaweCache.INSTANCE.createCache(
withInitial);
@Override

Datei anzeigen

@ -24,7 +24,7 @@ public class LazyBaseEntity extends BaseEntity {
Supplier<CompoundBinaryTag> tmp = saveTag;
if (tmp != null) {
saveTag = null;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
setNbt(tmp.get());
} else {
setNbt(TaskManager.taskManager().sync(tmp));

Datei anzeigen

@ -27,7 +27,7 @@ public class SlowExtent extends AbstractDelegateExtent {
increment += nanos;
if (increment >= THRESHOLD) {
long wait = increment / 1000000;
if (!Fawe.isMainThread()) {
if (!Fawe.isTickThread()) {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {

Datei anzeigen

@ -353,7 +353,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
}
public Future<?> addWriteTask(Runnable writeTask) {
return addWriteTask(writeTask, Fawe.isMainThread());
return addWriteTask(writeTask, Fawe.isTickThread());
}
public Future<?> addWriteTask(final Runnable writeTask, final boolean completeNow) {

Datei anzeigen

@ -317,7 +317,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
private <T> Future<T> sync(Runnable run, T value, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
run.run();
return Futures.immediateFuture(value);
}
@ -328,7 +328,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
private <T> Future<T> sync(Runnable run, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
run.run();
return Futures.immediateCancelledFuture();
}
@ -339,7 +339,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
private <T> Future<T> sync(Callable<T> call, Queue<FutureTask> queue) throws Exception {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return Futures.immediateFuture(call.call());
}
final FutureTask<T> result = new FutureTask<>(call);
@ -349,7 +349,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
private <T> Future<T> sync(Supplier<T> call, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return Futures.immediateFuture(call.get());
}
final FutureTask<T> result = new FutureTask<>(call::get);

Datei anzeigen

@ -239,7 +239,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
}
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
V result = (V) chunk.call();
if (result == null) {
return (V) (Future) Futures.immediateFuture(null);

Datei anzeigen

@ -205,7 +205,7 @@ public abstract class TaskManager {
*/
@Deprecated
public void taskNowMain(@Nonnull final Runnable runnable) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnable.run();
} else {
task(runnable);
@ -216,10 +216,10 @@ public abstract class TaskManager {
* Run a task as soon as possible not on the main thread.
*
* @param runnable the task to run
* @see Fawe#isMainThread()
* @see Fawe#isTickThread()
*/
public void taskNowAsync(@Nonnull final Runnable runnable) {
taskNow(runnable, Fawe.isMainThread());
taskNow(runnable, Fawe.isTickThread());
}
/**
@ -326,7 +326,7 @@ public abstract class TaskManager {
@Deprecated
public void taskWhenFree(@Nonnull Runnable run) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
run.run();
} else {
Fawe.instance().getQueueHandler().sync(run);
@ -340,7 +340,7 @@ public abstract class TaskManager {
*/
@Deprecated
public <T> T syncWhenFree(@Nonnull final RunnableVal<T> function) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
function.run();
return function.value;
}
@ -358,7 +358,7 @@ public abstract class TaskManager {
*/
@Deprecated
public <T> T syncWhenFree(@Nonnull final Supplier<T> supplier) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return supplier.get();
}
try {
@ -385,7 +385,7 @@ public abstract class TaskManager {
*/
@Deprecated
public <T> T sync(final Supplier<T> function) {
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return function.get();
}
try {

Datei anzeigen

@ -469,7 +469,7 @@ public final class EditSessionBuilder {
wnaMode = false;
if (unwrapped instanceof IQueueExtent) {
extent = queue = (IQueueExtent) unwrapped;
} else if (Settings.settings().QUEUE.PARALLEL_THREADS > 1 && !Fawe.isMainThread()) {
} else if (Settings.settings().QUEUE.PARALLEL_THREADS > 1 && !Fawe.isTickThread()) {
ParallelQueueExtent parallel = new ParallelQueueExtent(Fawe.instance().getQueueHandler(), world, fastMode);
queue = parallel.getExtent();
extent = parallel;