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 net.minecraft.world.level.block.state.BlockState blockState
) { ) {
int currentTick = MinecraftServer.currentTick; int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState, return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE) 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(); runnableVal.run();
} else { } else {
TaskManager.taskManager().sync(runnableVal); TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -204,7 +204,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) { if (nmsChunk != null) {
return nmsChunk; return nmsChunk;
} }
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
} else { } else {
@ -219,7 +219,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk; return nmsChunk;
} }
// Avoid "async" methods from the main thread. // Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true); 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 net.minecraft.world.level.block.state.BlockState blockState
) { ) {
int currentTick = MinecraftServer.currentTick; int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState, return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE) 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(); runnableVal.run();
} else { } else {
TaskManager.taskManager().sync(runnableVal); TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -220,7 +220,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) { if (nmsChunk != null) {
return nmsChunk; return nmsChunk;
} }
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
} else { } else {
@ -235,7 +235,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk; return nmsChunk;
} }
// Avoid "async" methods from the main thread. // Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true); 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 net.minecraft.world.level.block.state.BlockState blockState
) { ) {
int currentTick = MinecraftServer.currentTick; int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState, return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE) 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(); runnableVal.run();
} else { } else {
TaskManager.taskManager().sync(runnableVal); TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

@ -257,7 +257,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (nmsChunk != null) { if (nmsChunk != null) {
return nmsChunk; return nmsChunk;
} }
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
} else { } else {
@ -272,7 +272,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return nmsChunk; return nmsChunk;
} }
// Avoid "async" methods from the main thread. // Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ); return serverLevel.getChunk(chunkX, chunkZ);
} }
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true); 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 net.minecraft.world.level.block.state.BlockState blockState
) { ) {
int currentTick = (int) RegionizedServer.getGlobalTickData().getCurrentTick(); int currentTick = (int) RegionizedServer.getGlobalTickData().getCurrentTick();
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState, return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE) 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(); runnableVal.run();
} else { } else {
TaskManager.taskManager().sync(runnableVal); TaskManager.taskManager().sync(runnableVal);

Datei anzeigen

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

Datei anzeigen

@ -365,7 +365,7 @@ public class BukkitWorld extends AbstractWorld {
//FAWE start //FAWE start
int X = pt.getBlockX() >> 4; int X = pt.getBlockX() >> 4;
int Z = pt.getBlockZ() >> 4; int Z = pt.getBlockZ() >> 4;
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
world.getChunkAt(X, Z); world.getChunkAt(X, Z);
} else if (PaperLib.isPaper()) { } else if (PaperLib.isPaper()) {
PaperLib.getChunkAtAsync(world, X, Z, true); 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) { public <V> LongFunction<V> createMainThreadSafeCache(Supplier<V> withInitial) {
return new LongFunction<>() { 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); withInitial);
@Override @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -353,7 +353,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
} }
public Future<?> addWriteTask(Runnable writeTask) { public Future<?> addWriteTask(Runnable writeTask) {
return addWriteTask(writeTask, Fawe.isMainThread()); return addWriteTask(writeTask, Fawe.isTickThread());
} }
public Future<?> addWriteTask(final Runnable writeTask, final boolean completeNow) { 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) { private <T> Future<T> sync(Runnable run, T value, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
run.run(); run.run();
return Futures.immediateFuture(value); 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) { private <T> Future<T> sync(Runnable run, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
run.run(); run.run();
return Futures.immediateCancelledFuture(); 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 { private <T> Future<T> sync(Callable<T> call, Queue<FutureTask> queue) throws Exception {
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return Futures.immediateFuture(call.call()); return Futures.immediateFuture(call.call());
} }
final FutureTask<T> result = new FutureTask<>(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) { private <T> Future<T> sync(Supplier<T> call, Queue<FutureTask> queue) {
if (Fawe.isMainThread()) { if (Fawe.isTickThread()) {
return Futures.immediateFuture(call.get()); return Futures.immediateFuture(call.get());
} }
final FutureTask<T> result = new FutureTask<>(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(); V result = (V) chunk.call();
if (result == null) { if (result == null) {
return (V) (Future) Futures.immediateFuture(null); return (V) (Future) Futures.immediateFuture(null);

Datei anzeigen

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

Datei anzeigen

@ -469,7 +469,7 @@ public final class EditSessionBuilder {
wnaMode = false; wnaMode = false;
if (unwrapped instanceof IQueueExtent) { if (unwrapped instanceof IQueueExtent) {
extent = queue = (IQueueExtent) unwrapped; 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); ParallelQueueExtent parallel = new ParallelQueueExtent(Fawe.instance().getQueueHandler(), world, fastMode);
queue = parallel.getExtent(); queue = parallel.getExtent();
extent = parallel; extent = parallel;