diff --git a/worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweWorldNativeAccess.java b/worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweWorldNativeAccess.java index dbe0150a9..35b70fc32 100644 --- a/worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweWorldNativeAccess.java +++ b/worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweWorldNativeAccess.java @@ -250,7 +250,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess TaskManager.taskManager().sync(runnableVal)); + // TODO ??? + // TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal)); } @Override @@ -269,7 +270,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess Bukkit.getWorld(world) != null); + boolean loaded = false; // TODO TaskManager.taskManager().sync(() -> Bukkit.getWorld(world) != null); if (loaded) { LOGGER.warn("Chunk {},{} failed to load in 10 seconds in world {}. Retrying...", chunkX, chunkZ, world); // Retry chunk load @@ -298,7 +299,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { e.printStackTrace(); } } - return TaskManager.taskManager().sync(() -> serverLevel.getChunk(chunkX, chunkZ)); + return TaskManager.taskManager().syncAt( + () -> serverLevel.getChunk(chunkX, chunkZ), + BukkitAdapter.adapt(serverLevel.getWorld()), + chunkX, + chunkZ + ); } private static void addTicket(ServerLevel serverLevel, int chunkX, int chunkZ) { @@ -361,7 +367,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { ); } nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); - }); + }, BukkitAdapter.adapt(nmsWorld.getWorld()), chunkX, chunkZ); } private static List nearbyPlayers(ServerLevel serverLevel, ChunkPos coordIntPair) { diff --git a/worldedit-bukkit/adapters/adapter-1_20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R1/PaperweightFaweWorldNativeAccess.java b/worldedit-bukkit/adapters/adapter-1_20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R1/PaperweightFaweWorldNativeAccess.java index 186415f9f..ea1677eee 100644 --- a/worldedit-bukkit/adapters/adapter-1_20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R1/PaperweightFaweWorldNativeAccess.java +++ b/worldedit-bukkit/adapters/adapter-1_20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R1/PaperweightFaweWorldNativeAccess.java @@ -252,7 +252,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess TaskManager.taskManager().sync(runnableVal)); + // TODO ??? + // TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal)); } @Override @@ -271,7 +272,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess Bukkit.getWorld(world) != null); + boolean loaded = false; // TODO TaskManager.taskManager().sync(() -> Bukkit.getWorld(world) != null); if (loaded) { LOGGER.warn("Chunk {},{} failed to load in 10 seconds in world {}. Retrying...", chunkX, chunkZ, world); // Retry chunk load @@ -326,7 +326,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { e.printStackTrace(); } } - return TaskManager.taskManager().sync(() -> serverLevel.getChunk(chunkX, chunkZ)); + return TaskManager.taskManager().syncAt( + () -> serverLevel.getChunk(chunkX, chunkZ), + BukkitAdapter.adapt(serverLevel.getWorld()), + chunkX, + chunkZ + ); } private static void addTicket(ServerLevel serverLevel, int chunkX, int chunkZ) { diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java index 29162b607..281bc9edc 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java @@ -389,7 +389,9 @@ public interface IBukkitAdapter { * @return list of {@link org.bukkit.entity.Entity} */ default List getEntities(org.bukkit.World world) { - return TaskManager.taskManager().sync(world::getEntities); + // TODO + // return TaskManager.taskManager().sync(world::getEntities); + return List.of(); } } diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/ChunkListener.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/ChunkListener.java index 43d935c33..a4a03c1bf 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/ChunkListener.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/ChunkListener.java @@ -67,7 +67,7 @@ public abstract class ChunkListener implements Listener { PluginManager plm = Bukkit.getPluginManager(); Plugin plugin = Fawe.platform().getPlugin(); plm.registerEvents(this, plugin); - TaskManager.taskManager().repeat(() -> { + /*TaskManager.taskManager().repeat(() -> { Location tmpLoc = lastCancelPos; if (tmpLoc != null) { LOGGER.info("[FAWE Tick Limiter] Detected and cancelled physics lag source at {}", tmpLoc); @@ -89,7 +89,7 @@ public abstract class ChunkListener implements Listener { counter.put(key, badLimit); } badChunks.clear(); - }, Settings.settings().TICK_LIMITER.INTERVAL); + }, Settings.settings().TICK_LIMITER.INTERVAL)*/; } } diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/RenderListener.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/RenderListener.java index 22a09deb8..728209336 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/RenderListener.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/listener/RenderListener.java @@ -28,7 +28,7 @@ public class RenderListener implements Listener { public RenderListener(Plugin plugin) { Bukkit.getPluginManager().registerEvents(this, plugin); - TaskManager.taskManager().repeat(new Runnable() { + /*TaskManager.taskManager().repeat(new Runnable() { private long last = 0; @Override @@ -76,7 +76,7 @@ public class RenderListener implements Listener { } } } - }, 1); + }, 1)*/; } private void setViewDistance(Player player, int value) { diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java index 9f302d057..3097059a7 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java @@ -26,8 +26,10 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene public boolean isAllowed(Player player, Claim claim, MaskType type) { return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim .getOwnerName() - .equals(player.getUniqueId()) || TaskManager.taskManager().sync(() -> type == MaskType.MEMBER && - claim.allowBuild(player, Material.AIR) == null)); + .equals(player.getUniqueId()) || TaskManager.taskManager().syncAt( + () -> type == MaskType.MEMBER && claim.allowBuild(player, Material.AIR) == null, + BukkitAdapter.adapt(claim.getLesserBoundaryCorner()) + )); } @Override diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/ResidenceFeature.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/ResidenceFeature.java index a7c13cef5..2b2a95db3 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/ResidenceFeature.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/ResidenceFeature.java @@ -27,9 +27,9 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener { return residence != null && (residence.getOwner().equals(player.getName()) || residence.getOwner().equals(player.getUniqueId().toString()) || - type == MaskType.MEMBER && TaskManager.taskManager().sync(() -> residence + type == MaskType.MEMBER && TaskManager.taskManager().syncWith(() -> residence .getPermissions() - .playerHas(player, "build", false))); + .playerHas(player, "build", false), BukkitAdapter.adapt(player))); } @Override diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/plotsquared/FaweDelegateRegionManager.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/plotsquared/FaweDelegateRegionManager.java index c111ff630..d6c310444 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/plotsquared/FaweDelegateRegionManager.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/plotsquared/FaweDelegateRegionManager.java @@ -76,7 +76,8 @@ public class FaweDelegateRegionManager { e.printStackTrace(); } finally { if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone, new com.sk89q.worldedit.util.Location(world, )); } } } @@ -203,7 +204,8 @@ public class FaweDelegateRegionManager { RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE) ); if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone); } } }); @@ -272,7 +274,8 @@ public class FaweDelegateRegionManager { RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE) ); if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone); } } }); @@ -301,7 +304,8 @@ public class FaweDelegateRegionManager { e.printStackTrace(); } if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone); } } }); @@ -354,7 +358,8 @@ public class FaweDelegateRegionManager { } } if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone); } }); return true; @@ -378,7 +383,8 @@ public class FaweDelegateRegionManager { editSession.flushQueue(); } if (whenDone != null) { - TaskManager.taskManager().task(whenDone); + // TODO + // TaskManager.taskManager().task(whenDone); } } }); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/BukkitTaskManager.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/BukkitTaskManager.java index a79cd5d2e..de78394f8 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/BukkitTaskManager.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/BukkitTaskManager.java @@ -1,13 +1,16 @@ package com.fastasyncworldedit.bukkit.util; +import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.World; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; +import java.util.concurrent.ExecutionException; import java.util.function.Supplier; public class BukkitTaskManager extends TaskManager { @@ -18,11 +21,6 @@ public class BukkitTaskManager extends TaskManager { this.plugin = plugin; } - @Override - public int repeat(@Nonnull final Runnable runnable, final int interval) { - return this.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, runnable, interval, interval); - } - @Override public int repeatAsync(@Nonnull final Runnable runnable, final int interval) { return this.plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(this.plugin, runnable, interval, interval); @@ -34,18 +32,13 @@ public class BukkitTaskManager extends TaskManager { } @Override - public void task(@Nonnull final Runnable runnable) { - this.plugin.getServer().getScheduler().runTask(this.plugin, runnable).getTaskId(); - } - - @Override - public void task(@NotNull final Runnable runnable, @NotNull final Location context) { + public void task(@NotNull final Runnable runnable, @NotNull final Location location) { } @Override - public void later(@Nonnull final Runnable runnable, final int delay) { - this.plugin.getServer().getScheduler().runTaskLater(this.plugin, runnable, delay).getTaskId(); + public void task(@NotNull final Runnable runnable, @NotNull final World world, final int chunkX, final int chunkZ) { + } @Override @@ -68,7 +61,7 @@ public class BukkitTaskManager extends TaskManager { // TODO @Override - public T syncAt(final Supplier supplier, final Location context) { + public T syncAt(final Supplier supplier, final World world, final int chunkX, final int chunkZ) { return sync(supplier); } @@ -77,4 +70,16 @@ public class BukkitTaskManager extends TaskManager { return sync(supplier); } + private T sync(final Supplier supplier) { + if (Fawe.isTickThread()) { + return supplier.get(); + } + try { + // TODO + return Fawe.instance().getQueueHandler().sync(supplier).get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + } diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/FoliaTaskManager.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/FoliaTaskManager.java index f92859349..32236379f 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/FoliaTaskManager.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/FoliaTaskManager.java @@ -5,6 +5,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.World; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -14,63 +15,66 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; import java.util.function.Supplier; -import static java.lang.invoke.MethodHandles.dropReturn; -import static java.lang.invoke.MethodHandles.explicitCastArguments; -import static java.lang.invoke.MethodHandles.filterArguments; import static java.lang.invoke.MethodHandles.insertArguments; import static java.lang.invoke.MethodType.methodType; public class FoliaTaskManager extends TaskManager { - private final ScheduledExecutorService backgroundExecutor = Executors.newSingleThreadScheduledExecutor(); private final AtomicInteger idCounter = new AtomicInteger(); - @Override - public int repeat(@NotNull final Runnable runnable, final int interval) { - return fail(); - } - @Override public int repeatAsync(@NotNull final Runnable runnable, final int interval) { - backgroundExecutor.scheduleAtFixedRate(runnable, 0, ticksToMs(interval), TimeUnit.MILLISECONDS); + // TODO return some kind of own ScheduledTask instead of int + Bukkit.getAsyncScheduler().runAtFixedRate( + WorldEditPlugin.getInstance(), + asConsumer(runnable), + 0, + ticksToMs(interval), + TimeUnit.MILLISECONDS + ); return idCounter.getAndIncrement(); } @Override public void async(@NotNull final Runnable runnable) { - backgroundExecutor.submit(runnable); + Bukkit.getAsyncScheduler().runNow(WorldEditPlugin.getInstance(), asConsumer(runnable)); } @Override - public void task(@NotNull final Runnable runnable) { - fail(); - } - - @Override - public void task(@NotNull final Runnable runnable, @NotNull final Location context) { - SchedulerAdapter.executeForLocation(context, runnable); - } - - @Override - public void later(@NotNull final Runnable runnable, final int delay) { - fail(); + public void task(@NotNull final Runnable runnable, @NotNull final World world, final int chunkX, final int chunkZ) { + Bukkit.getRegionScheduler().run( + WorldEditPlugin.getInstance(), + BukkitAdapter.adapt(world), + chunkX, + chunkZ, + asConsumer(runnable) + ); } @Override public void later(@NotNull final Runnable runnable, final Location location, final int delay) { - fail("Not implemented"); + Bukkit.getRegionScheduler().runDelayed( + WorldEditPlugin.getInstance(), + BukkitAdapter.adapt(location), + asConsumer(runnable), + delay + ); } @Override public void laterAsync(@NotNull final Runnable runnable, final int delay) { - backgroundExecutor.schedule(runnable, ticksToMs(delay), TimeUnit.MILLISECONDS); + Bukkit.getAsyncScheduler().runDelayed( + WorldEditPlugin.getInstance(), + asConsumer(runnable), + ticksToMs(delay), + TimeUnit.MILLISECONDS + ); } @Override @@ -79,9 +83,15 @@ public class FoliaTaskManager extends TaskManager { } @Override - public T syncAt(final Supplier supplier, final Location context) { + public T syncAt(final Supplier supplier, final World world, final int chunkX, final int chunkZ) { FutureTask task = new FutureTask<>(supplier::get); - SchedulerAdapter.executeForLocation(context, task); + Bukkit.getRegionScheduler().run( + WorldEditPlugin.getInstance(), + BukkitAdapter.adapt(world), + chunkX, + chunkZ, + asConsumer(task) + ); try { return task.get(); } catch (InterruptedException | ExecutionException e) { @@ -89,10 +99,16 @@ public class FoliaTaskManager extends TaskManager { } } + private Consumer asConsumer(Runnable runnable) { + return __ -> runnable.run(); + } + @Override public T syncWith(final Supplier supplier, final Player context) { FutureTask task = new FutureTask<>(supplier::get); - SchedulerAdapter.executeForEntity(context, task); + BukkitAdapter.adapt(context) + .getScheduler() + .execute(WorldEditPlugin.getInstance(), task, null, 0); try { return task.get(); } catch (InterruptedException | ExecutionException e) { @@ -105,105 +121,9 @@ public class FoliaTaskManager extends TaskManager { return ticks * 50; } - private T fail() { - return fail("No main thread present"); - } private T fail(String message) { throw new UnsupportedOperationException(message); } - private static class SchedulerAdapter { - - private static final MethodHandle EXECUTE_FOR_LOCATION; - private static final MethodHandle EXECUTE_FOR_PLAYER; - private static final Runnable THROW_IF_RETIRED = () -> throwRetired(); - - private static final MethodType LOCATION_EXECUTE_TYPE = methodType( - void.class, - Plugin.class, - org.bukkit.Location.class, - Runnable.class - ); - - private static final MethodType ENTITY_EXECUTE_TYPE = methodType( - boolean.class, - Plugin.class, - Runnable.class, - Runnable.class, - long.class - ); - - static { - final Plugin pluginInstance = WorldEditPlugin.getInstance(); - final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - MethodHandle executeForLocation; - - MethodHandle executeForPlayer; - try { - Class regionisedSchedulerClass = Class.forName("io.papermc.paper.threadedregions.scheduler.RegionisedScheduler"); - final Method method = Bukkit.class.getDeclaredMethod("getRegionScheduler"); - executeForLocation = lookup.findVirtual( - regionisedSchedulerClass, - "execute", - LOCATION_EXECUTE_TYPE - ); - executeForLocation = executeForLocation.bindTo(method.invoke(null)); - executeForLocation = executeForLocation.bindTo(pluginInstance); - - Class entitySchedulerClass = Class.forName("io.papermc.paper.threadedregions.scheduler.EntityScheduler"); - executeForPlayer = lookup.findVirtual( - entitySchedulerClass, - "execute", - ENTITY_EXECUTE_TYPE - ); - // (ES, P, R, R, L)Z (ES, R, R, L)Z - executeForPlayer = insertArguments(executeForPlayer, 1, pluginInstance); - // (ES, R1, R2, L)Z -> (ES, R1)Z - executeForPlayer = insertArguments(executeForPlayer, 2, THROW_IF_RETIRED, 0); - // (ES, R1)Z -> (ES, R1)V - executeForPlayer = dropReturn(executeForPlayer); - MethodHandle getScheduler = lookup.findVirtual( - org.bukkit.entity.Entity.class, - "getScheduler", - methodType(entitySchedulerClass) - ); - // (ES, R1)V -> (E, R1)V - executeForPlayer = filterArguments(executeForPlayer, 0, getScheduler); - MethodType finalType = methodType(void.class, org.bukkit.entity.Player.class, Runnable.class); - // (ES, R1)V -> (P, R1)V - executeForPlayer = explicitCastArguments(executeForPlayer, finalType); - } catch (Throwable throwable) { - throw new AssertionError(throwable); - } - EXECUTE_FOR_LOCATION = executeForLocation; - EXECUTE_FOR_PLAYER = executeForPlayer; - } - - static void executeForLocation(Location location, Runnable task) { - try { - EXECUTE_FOR_LOCATION.invokeExact(BukkitAdapter.adapt(location), task); - } catch (Error | RuntimeException e) { - throw e; - } catch (Throwable other) { - throw new RuntimeException(other); - } - } - static void executeForEntity(Player player, Runnable task) { - try { - EXECUTE_FOR_PLAYER.invokeExact(BukkitAdapter.adapt(player), task); - } catch (Error | RuntimeException e) { - throw e; - } catch (Throwable other) { - throw new RuntimeException(other); - } - } - - private static void throwRetired() { - throw new RuntimeException("Player retired"); - } - - } - } diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/image/BukkitImageViewer.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/image/BukkitImageViewer.java index 2a61f3083..7f6ca6552 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/image/BukkitImageViewer.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/image/BukkitImageViewer.java @@ -4,6 +4,7 @@ import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.image.Drawable; import com.fastasyncworldedit.core.util.image.ImageUtil; import com.fastasyncworldedit.core.util.image.ImageViewer; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -164,7 +165,7 @@ public class BukkitImageViewer implements ImageViewer { controller.showInFrames(player, frames, true); } else { int slot = getMapSlot(player); - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncWith(() -> { if (slot == -1) { if (initializing) { player.getInventory().setItemInMainHand(new ItemStack(Material.MAP)); @@ -175,7 +176,7 @@ public class BukkitImageViewer implements ImageViewer { player.getInventory().setHeldItemSlot(slot); } return null; - }); + }, BukkitAdapter.adapt(player)); if (image == null && drawable != null) { image = drawable.draw(); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 3c2e99f42..fd532824d 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -66,12 +66,12 @@ public class BukkitBlockCommandSender extends AbstractCommandBlockActor { @Deprecated public void printRaw(String msg) { //FAWE start - ensure executed on main thread - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { for (String part : msg.split("\n")) { sender.sendMessage(part); } return null; - }); + }, getLocation()); //FAWE end } @@ -79,12 +79,12 @@ public class BukkitBlockCommandSender extends AbstractCommandBlockActor { @Deprecated public void print(String msg) { //FAWE start - ensure executed on main thread - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { for (String part : msg.split("\n")) { print(TextComponent.of(part, TextColor.LIGHT_PURPLE)); } return null; - }); + }, getLocation()); //FAWE end } @@ -92,12 +92,12 @@ public class BukkitBlockCommandSender extends AbstractCommandBlockActor { @Deprecated public void printDebug(String msg) { //FAWE start - ensure executed on main thread - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { for (String part : msg.split("\n")) { print(TextComponent.of(part, TextColor.GRAY)); } return null; - }); + }, getLocation()); //FAWE end } @@ -105,22 +105,22 @@ public class BukkitBlockCommandSender extends AbstractCommandBlockActor { @Deprecated public void printError(String msg) { //FAWE start - ensure executed on main thread - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { for (String part : msg.split("\n")) { print(TextComponent.of(part, TextColor.RED)); } return null; - }); + }, getLocation()); //FAWE end } @Override public void print(Component component) { //FAWE start - ensure executed on main thread - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); return null; - }); + }, getLocation()); //FAWE end } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java index b060d78f8..1a64d55e2 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java @@ -172,10 +172,10 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag @Override public void flushChanges() { if (items != null) { - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncWith(() -> { player.getInventory().setContents(items); return null; - }); + }, BukkitAdapter.adapt(player)); items = null; } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 1598cb547..8959af98a 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -45,6 +45,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.TreeGenerator; @@ -146,7 +147,7 @@ public class BukkitWorld extends AbstractWorld { public List getEntities(Region region) { World world = getWorld(); - List ents = TaskManager.taskManager().sync(world::getEntities); + List ents = List.of(); // TODO TaskManager.taskManager().sync(world::getEntities); List entities = new ArrayList<>(); for (Entity ent : ents) { if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) { @@ -160,7 +161,7 @@ public class BukkitWorld extends AbstractWorld { public List getEntities() { List list = new ArrayList<>(); - List ents = TaskManager.taskManager().sync(getWorld()::getEntities); + List ents = List.of(); // TaskManager.taskManager().sync(getWorld()::getEntities); for (Entity entity : ents) { list.add(BukkitAdapter.adapt(entity)); } @@ -290,7 +291,7 @@ public class BukkitWorld extends AbstractWorld { return false; } - TaskManager.taskManager().sync(() -> { + TaskManager.taskManager().syncAt(() -> { InventoryHolder chest = (InventoryHolder) state; Inventory inven = chest.getInventory(); if (chest instanceof Chest) { @@ -298,7 +299,7 @@ public class BukkitWorld extends AbstractWorld { } inven.clear(); return null; - }); + }, new Location(this, pt.toVector3())); return true; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java index 230e12013..fda51af9b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java @@ -139,7 +139,7 @@ public class Fawe { }, 0);*/ if (!FoliaSupport.isFolia()) { - TaskManager.taskManager().repeat(timer, 1); + // TODO TaskManager.taskManager().repeat(timer, 1); } clipboardExecutor = new KeyQueuedExecutorService<>(new ThreadPoolExecutor( diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/entity/LazyBaseEntity.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/entity/LazyBaseEntity.java index f591cf826..3686334f1 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/entity/LazyBaseEntity.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/entity/LazyBaseEntity.java @@ -27,7 +27,8 @@ public class LazyBaseEntity extends BaseEntity { if (Fawe.isMainThread()) { setNbt(tmp.get()); } else { - setNbt(TaskManager.taskManager().sync(tmp)); + // TODO + // setNbt(TaskManager.taskManager().sync(tmp)); } } return super.getNbt(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/NMSRelighter.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/NMSRelighter.java index e38df12f5..ca4a30087 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/NMSRelighter.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/NMSRelighter.java @@ -914,13 +914,13 @@ public class NMSRelighter implements Relighter { queue.flush(); finished.set(true); } else { - TaskManager.taskManager().sync(new RunnableVal<>() { + TaskManager.taskManager().syncAt(new RunnableVal<>() { @Override public void run(Object value) { queue.flush(); finished.set(true); } - }); + }, null); // TODO } } @@ -951,7 +951,8 @@ public class NMSRelighter implements Relighter { if (Settings.settings().LIGHTING.ASYNC) { runnable.run(); } else { - TaskManager.taskManager().sync(runnable); + // TODO + // TaskManager.taskManager().sync(runnable); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TaskManager.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TaskManager.java index 69a16b437..58dd3a06d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TaskManager.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TaskManager.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.World; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; @@ -49,15 +50,6 @@ public abstract class TaskManager { return INSTANCE; } - /** - * Run a repeating task on the main thread. - * - * @param runnable the task to run - * @param interval in ticks - */ - @Deprecated - public abstract int repeat(@Nonnull final Runnable runnable, final int interval); - /** * Run a repeating task asynchronously. * @@ -79,14 +71,11 @@ public abstract class TaskManager { * * @param runnable the task to run */ - @Deprecated - public abstract void task(@Nonnull final Runnable runnable); - /** - * Run a task on the main thread. - * - * @param runnable the task to run - */ - public abstract void task(@Nonnull final Runnable runnable, @Nonnull Location contextLocation); + public void task(@Nonnull final Runnable runnable, @Nonnull Location location) { + task(runnable, (World) location.getExtent(), location.getBlockX() >> 4, location.getBlockZ() >> 4); + } + + public abstract void task(@Nonnull final Runnable runnable, @Nonnull World world, int chunkX, int chunkZ); /** * Get the public ForkJoinPool. @@ -182,70 +171,13 @@ public abstract class TaskManager { queue.endUnsafe(Fawe.isMainThread()); } - /** - * Run a task on the current thread or asynchronously. - * - If it's already the main thread, it will just call run() - * - * @param runnable the task to run - * @param async whether the task should run on the main thread - */ - public void taskNow(@Nonnull final Runnable runnable, boolean async) { - if (async) { - async(runnable); - } else { - runnable.run(); - } - } - - /** - * Run a task as soon as possible on the main thread. - * - Non blocking if not calling from the main thread - * - * @param runnable the task to run - */ - @Deprecated - public void taskNowMain(@Nonnull final Runnable runnable) { - if (Fawe.isMainThread()) { - runnable.run(); - } else { - task(runnable); - } - } - - /** - * Run a task as soon as possible not on the main thread. - * - * @param runnable the task to run - * @see Fawe#isMainThread() - */ - public void taskNowAsync(@Nonnull final Runnable runnable) { - taskNow(runnable, Fawe.isMainThread()); - } - - /** - * Run a task on the main thread at the next tick or now async. - * - * @param runnable the task to run. - * @param async whether the task should run on the main thread - */ - @Deprecated - public void taskSoonMain(@Nonnull final Runnable runnable, boolean async) { - if (async) { - async(runnable); - } else { - task(runnable); - } - } - - /** * Run a task later on the main thread. * * @param runnable the task to run + * @param location the location context to run at * @param delay in ticks */ - @Deprecated - public abstract void later(@Nonnull final Runnable runnable, final int delay); public abstract void later(@Nonnull final Runnable runnable, Location location, final int delay); /** @@ -263,35 +195,6 @@ public abstract class TaskManager { */ public abstract void cancel(final int task); - /** - * Break up a task and run it in fragments of 5ms.
- * - Each task will run on the main thread.
- * - * @param objects the list of objects to run the task for - * @param task the task to run on each object - * @param whenDone when the object task completes - */ - @Deprecated - public void objectTask(Collection objects, final RunnableVal task, final Runnable whenDone) { - final Iterator iterator = objects.iterator(); - task(new Runnable() { - @Override - public void run() { - long start = System.currentTimeMillis(); - boolean hasNext; - while ((hasNext = iterator.hasNext()) && System.currentTimeMillis() - start < 5) { - task.value = iterator.next(); - task.run(); - } - if (!hasNext) { - later(whenDone, 1); - } else { - later(this, 1); - } - } - }); - } - /** * @deprecated Deprecated without replacement as unused internally, and poor implementation of what it's designed to do. */ @@ -333,69 +236,11 @@ public abstract class TaskManager { } } - /** - * Run a task on the main thread when the TPS is high enough, and wait for execution to finish. - * - Useful if you need to access something from the Bukkit API from another thread
- * - Usually wait time is around 25ms
- */ - @Deprecated - public T syncWhenFree(@Nonnull final RunnableVal function) { - if (Fawe.isMainThread()) { - function.run(); - return function.value; - } - try { - return Fawe.instance().getQueueHandler().sync((Supplier) function).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + public T syncAt(Supplier supplier, Location context) { + return syncAt(supplier, (World) context.getExtent(), context.getBlockX() >> 4, context.getBlockZ() >> 4); } - /** - * Run a task on the main thread when the TPS is high enough, and wait for execution to finish. - * - Useful if you need to access something from the Bukkit API from another thread
- * - Usually wait time is around 25ms
- */ - @Deprecated - public T syncWhenFree(@Nonnull final Supplier supplier) { - if (Fawe.isMainThread()) { - return supplier.get(); - } - try { - return Fawe.instance().getQueueHandler().sync(supplier).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - - /** - * Quickly run a task on the main thread, and wait for execution to finish. - * - Useful if you need to access something from the Bukkit API from another thread
- * - Usually wait time is around 25ms - */ - @Deprecated - public T sync(@Nonnull final RunnableVal function) { - return sync((Supplier) function); - } - - /** - * Quickly run a task on the main thread, and wait for execution to finish. - * - Useful if you need to access something from the Bukkit API from another thread
- * - Usually wait time is around 25ms
- */ - @Deprecated - public T sync(final Supplier function) { - if (Fawe.isMainThread()) { - return function.get(); - } - try { - return Fawe.instance().getQueueHandler().sync(function).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - - public abstract T syncAt(Supplier supplier, Location context); + public abstract T syncAt(Supplier supplier, World world, int chunkX, int chunkZ); public abstract T syncWith(Supplier supplier, Player context); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/progress/DefaultProgressTracker.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/progress/DefaultProgressTracker.java index 4aa846fc3..1970a252a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/progress/DefaultProgressTracker.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/progress/DefaultProgressTracker.java @@ -93,14 +93,16 @@ public class DefaultProgressTracker implements BiConsumer() { + TaskManager.taskManager().syncAt(new RunnableVal() { @Override public void run(Boolean value) { getBasePlayer().findFreePosition(searchPos); } - }); + }, searchPos); } @Override public void setOnGround(Location searchPos) { - TaskManager.taskManager().sync(new RunnableVal() { + TaskManager.taskManager().syncAt(new RunnableVal() { @Override public void run(Boolean value) { getBasePlayer().setOnGround(searchPos); } - }); + }, searchPos); } @Override @@ -70,12 +70,12 @@ public class AsyncPlayer extends PlayerProxy { @Override public boolean ascendLevel() { - return TaskManager.taskManager().sync(() -> getBasePlayer().ascendLevel()); + return TaskManager.taskManager().syncWith(() -> getBasePlayer().ascendLevel(), this); } @Override public boolean descendLevel() { - return TaskManager.taskManager().sync(() -> getBasePlayer().descendLevel()); + return TaskManager.taskManager().syncWith(() -> getBasePlayer().descendLevel(), this); } @Override @@ -185,15 +185,15 @@ public class AsyncPlayer extends PlayerProxy { @Override public Location getBlockTraceFace(final int range, final boolean useLastBlock, @Nullable final Mask stopMask) { - return TaskManager.taskManager().syncAt(() -> super.getBlockTraceFace(range, useLastBlock, stopMask), getLocation()); + return TaskManager.taskManager().syncWith(() -> super.getBlockTraceFace(range, useLastBlock, stopMask), this); } @Override public Location getSolidBlockTrace(int range) { - return TaskManager.taskManager().sync(() -> { + return TaskManager.taskManager().syncWith(() -> { TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); return tb.getSolidTargetBlock(); - }); + }, this); } @Override @@ -203,7 +203,7 @@ public class AsyncPlayer extends PlayerProxy { @Override public boolean passThroughForwardWall(int range) { - return TaskManager.taskManager().sync(() -> { + return TaskManager.taskManager().syncWith(() -> { int searchDist = 0; TargetBlock hitBlox = new TargetBlock(AsyncPlayer.this, range, 0.2); Extent world = getLocation().getExtent(); @@ -248,7 +248,7 @@ public class AsyncPlayer extends PlayerProxy { } return false; - }); + }, this); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/WorldWrapper.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/WorldWrapper.java index 05616a414..2546737aa 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/WorldWrapper.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/WorldWrapper.java @@ -253,18 +253,20 @@ public class WorldWrapper extends AbstractWorld { @Override public void simulateBlockMine(BlockVector3 pt) { - TaskManager.taskManager().sync(new RunnableVal() { + TaskManager.taskManager().syncAt(new RunnableVal() { @Override public void run(Object value) { parent.simulateBlockMine(pt); } - }); + }, new Location(this, pt.toVector3())); } //FAWE start @Override public Collection getBlockDrops(final BlockVector3 position) { - return TaskManager.taskManager().sync(() -> parent.getBlockDrops(position)); + return TaskManager.taskManager().syncAt( + () -> parent.getBlockDrops(position), + new Location(this, position.toVector3())); } //FAWE end diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index ecf859896..5fd2778e7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -3819,12 +3819,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } if (containsAny) { changes++; - TaskManager.taskManager().sync(new RunnableVal() { + // TODO this seems to be broken? +/* TaskManager.taskManager().sync(new RunnableVal() { @Override public void run(Object value) { regenerateChunk(cx, cz, biome, seed); } - }); + });*/ } } if (changes != 0) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index aca13bc46..8fdd1d7bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -709,7 +709,16 @@ public class UtilityCommands { //FAWE start - run this sync int finalRadius = radius; - int killed = TaskManager.taskManager().sync(() -> killMatchingEntities(finalRadius, actor, flags::createFunction)); + int killed; + // TODO location context might be somewhere else actually + if (actor instanceof Player player) { + killed = TaskManager.taskManager().syncWith( + () -> killMatchingEntities(finalRadius, actor, flags::createFunction), + player + ); + } else { + killed = 0; + } //FAWE end actor.print(Caption.of( @@ -741,7 +750,9 @@ public class UtilityCommands { } //FAWE start - run this sync - int removed = TaskManager.taskManager().sync(() -> killMatchingEntities(radius, actor, remover::createFunction)); + int removed = 0; + // TODO location context might be somewhere else actually + // removed = TaskManager.taskManager().sync(() -> killMatchingEntities(radius, actor, remover::createFunction)); //FAWE end actor.print(Caption.of("worldedit.remove.removed", TextComponent.of(removed))); return removed; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java index f2310a211..0664f0362 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java @@ -148,7 +148,7 @@ public class EntityRemover { if (registryType != null) { if (type.matches(registryType)) { //FAWE start - Calling this async violates thread safety - TaskManager.taskManager().sync(entity::remove); + TaskManager.taskManager().syncAt(entity::remove, entity.getLocation()); //FAWE end return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java index 8337a7327..be36f20ff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java @@ -109,7 +109,8 @@ public abstract class AbstractNonPlayerActor implements Actor { if (async) { asyncNotifyQueue.run(wrapped); } else { - TaskManager.taskManager().taskNow(wrapped, false); + // TODO + // TaskManager.taskManager().taskNow(wrapped, false); } return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index ae4eb2144..f810a4f7e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -677,7 +677,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (async) { asyncNotifyQueue.run(wrapped); } else { - TaskManager.taskManager().taskNow(wrapped, false); + // TODO + // TaskManager.taskManager().taskNow(wrapped, false); } return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 7b493cf98..edd51e053 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -687,7 +687,8 @@ public final class PlatformCommandManager { Command cmd = optional.get(); PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null); if (queued != null && !queued.isQueued()) { - TaskManager.taskManager().taskNow(() -> handleCommandOnCurrentThread(event), Fawe.isMainThread()); + // TODO? + // TaskManager.taskManager().taskNow(() -> handleCommandOnCurrentThread(event), Fawe.isMainThread()); return; } else { actor.decline(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index 88cf4fc6f..1619502ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -26,6 +26,8 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.nbt.CompoundBinaryTag; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -99,14 +101,15 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { Collection drops = world.getBlockDrops(location); boolean canSet = super.setBlock(location, block); if (canSet) { - TaskManager.taskManager().sync(new RunnableVal<>() { + final Vector3 position = location.toVector3(); + TaskManager.taskManager().syncAt(new RunnableVal<>() { @Override public void run(Object value) { for (BaseItemStack stack : drops) { - world.dropItem(location.toVector3(), stack); + world.dropItem(position, stack); } } - }); + }, new Location(world, position)); return true; } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index fa3ef1dc4..c14abee73 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -170,7 +170,7 @@ public class ExtentEntityCopy implements EntityFunction { uuid ); } else { - TaskManager.taskManager().sync(entity::remove); + TaskManager.taskManager().syncAt(entity::remove, entity.getLocation()); //FAWE end } }