Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-17 00:20:09 +01:00
tmp
Dieser Commit ist enthalten in:
Ursprung
54a96bcaea
Commit
fca4ab42ef
@ -250,7 +250,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
|
||||
}
|
||||
}
|
||||
};
|
||||
TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
|
||||
// TODO ???
|
||||
// TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -269,7 +270,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
|
||||
if (Fawe.isMainThread()) {
|
||||
runnableVal.run();
|
||||
} else {
|
||||
TaskManager.taskManager().sync(runnableVal);
|
||||
// TODO
|
||||
// TaskManager.taskManager().sync(runnableVal);
|
||||
}
|
||||
cachedChanges.clear();
|
||||
cachedChunksToSend.clear();
|
||||
|
@ -11,6 +11,7 @@ import com.fastasyncworldedit.core.util.MathMan;
|
||||
import com.fastasyncworldedit.core.util.ReflectionUtils;
|
||||
import com.fastasyncworldedit.core.util.TaskManager;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.Refraction;
|
||||
@ -283,7 +284,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||
} catch (TimeoutException e) {
|
||||
String world = serverLevel.getWorld().getName();
|
||||
// We've already taken 10 seconds we can afford to wait a little here.
|
||||
boolean loaded = TaskManager.taskManager().sync(() -> 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<ServerPlayer> nearbyPlayers(ServerLevel serverLevel, ChunkPos coordIntPair) {
|
||||
|
@ -252,7 +252,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
|
||||
}
|
||||
}
|
||||
};
|
||||
TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
|
||||
// TODO ???
|
||||
// TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -271,7 +272,8 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
|
||||
if (Fawe.isMainThread()) {
|
||||
runnableVal.run();
|
||||
} else {
|
||||
TaskManager.taskManager().sync(runnableVal);
|
||||
// TODO
|
||||
// TaskManager.taskManager().sync(runnableVal);
|
||||
}
|
||||
cachedChanges.clear();
|
||||
cachedChunksToSend.clear();
|
||||
|
@ -311,7 +311,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||
} catch (TimeoutException e) {
|
||||
String world = serverLevel.getWorld().getName();
|
||||
// We've already taken 10 seconds we can afford to wait a little here.
|
||||
boolean loaded = TaskManager.taskManager().sync(() -> 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) {
|
||||
|
@ -389,7 +389,9 @@ public interface IBukkitAdapter {
|
||||
* @return list of {@link org.bukkit.entity.Entity}
|
||||
*/
|
||||
default List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
|
||||
return TaskManager.taskManager().sync(world::getEntities);
|
||||
// TODO
|
||||
// return TaskManager.taskManager().sync(world::getEntities);
|
||||
return List.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public abstract class ChunkListener implements Listener {
|
||||
PluginManager plm = Bukkit.getPluginManager();
|
||||
Plugin plugin = Fawe.<FaweBukkit>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)*/;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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> T syncAt(final Supplier<T> supplier, final Location context) {
|
||||
public <T> T syncAt(final Supplier<T> 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> T sync(final Supplier<T> supplier) {
|
||||
if (Fawe.isTickThread()) {
|
||||
return supplier.get();
|
||||
}
|
||||
try {
|
||||
// TODO
|
||||
return Fawe.instance().getQueueHandler().sync(supplier).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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> T syncAt(final Supplier<T> supplier, final Location context) {
|
||||
public <T> T syncAt(final Supplier<T> supplier, final World world, final int chunkX, final int chunkZ) {
|
||||
FutureTask<T> 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 <R> Consumer<R> asConsumer(Runnable runnable) {
|
||||
return __ -> runnable.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T syncWith(final Supplier<T> supplier, final Player context) {
|
||||
FutureTask<T> 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> T fail() {
|
||||
return fail("No main thread present");
|
||||
}
|
||||
|
||||
private <T> 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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<com.sk89q.worldedit.entity.Entity> getEntities(Region region) {
|
||||
World world = getWorld();
|
||||
|
||||
List<Entity> ents = TaskManager.taskManager().sync(world::getEntities);
|
||||
List<Entity> ents = List.of(); // TODO TaskManager.taskManager().sync(world::getEntities);
|
||||
List<com.sk89q.worldedit.entity.Entity> 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<com.sk89q.worldedit.entity.Entity> getEntities() {
|
||||
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
|
||||
|
||||
List<Entity> ents = TaskManager.taskManager().sync(getWorld()::getEntities);
|
||||
List<Entity> 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;
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.<br>
|
||||
* - Each task will run on the main thread.<br>
|
||||
*
|
||||
* @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 <T> void objectTask(Collection<T> objects, final RunnableVal<T> task, final Runnable whenDone) {
|
||||
final Iterator<T> 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<br>
|
||||
* - Usually wait time is around 25ms<br>
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T syncWhenFree(@Nonnull final RunnableVal<T> function) {
|
||||
if (Fawe.isMainThread()) {
|
||||
function.run();
|
||||
return function.value;
|
||||
}
|
||||
try {
|
||||
return Fawe.instance().getQueueHandler().sync((Supplier<T>) function).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public <T> T syncAt(Supplier<T> 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<br>
|
||||
* - Usually wait time is around 25ms<br>
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T syncWhenFree(@Nonnull final Supplier<T> 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<br>
|
||||
* - Usually wait time is around 25ms
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T sync(@Nonnull final RunnableVal<T> function) {
|
||||
return sync((Supplier<T>) 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<br>
|
||||
* - Usually wait time is around 25ms<br>
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T sync(final Supplier<T> 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> T syncAt(Supplier<T> supplier, Location context);
|
||||
public abstract <T> T syncAt(Supplier<T> supplier, World world, int chunkX, int chunkZ);
|
||||
|
||||
public abstract <T> T syncWith(Supplier<T> supplier, Player context);
|
||||
|
||||
|
@ -93,14 +93,16 @@ public class DefaultProgressTracker implements BiConsumer<DefaultProgressTracker
|
||||
}
|
||||
|
||||
private void done() {
|
||||
TaskManager.taskManager().task(this::doneTask);
|
||||
// TODO
|
||||
// TaskManager.taskManager().task(this::doneTask);
|
||||
}
|
||||
|
||||
private long lastTick = 0;
|
||||
|
||||
private void send() {
|
||||
// Run on main thread
|
||||
TaskManager.taskManager().task(this::sendTask);
|
||||
// TODO
|
||||
// TaskManager.taskManager().task(this::sendTask);
|
||||
}
|
||||
|
||||
public void doneTask() {
|
||||
|
@ -40,22 +40,22 @@ public class AsyncPlayer extends PlayerProxy {
|
||||
|
||||
@Override
|
||||
public void findFreePosition(Location searchPos) {
|
||||
TaskManager.taskManager().sync(new RunnableVal<Boolean>() {
|
||||
TaskManager.taskManager().syncAt(new RunnableVal<Boolean>() {
|
||||
@Override
|
||||
public void run(Boolean value) {
|
||||
getBasePlayer().findFreePosition(searchPos);
|
||||
}
|
||||
});
|
||||
}, searchPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnGround(Location searchPos) {
|
||||
TaskManager.taskManager().sync(new RunnableVal<Boolean>() {
|
||||
TaskManager.taskManager().syncAt(new RunnableVal<Boolean>() {
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -253,18 +253,20 @@ public class WorldWrapper extends AbstractWorld {
|
||||
|
||||
@Override
|
||||
public void simulateBlockMine(BlockVector3 pt) {
|
||||
TaskManager.taskManager().sync(new RunnableVal<Object>() {
|
||||
TaskManager.taskManager().syncAt(new RunnableVal<Object>() {
|
||||
@Override
|
||||
public void run(Object value) {
|
||||
parent.simulateBlockMine(pt);
|
||||
}
|
||||
});
|
||||
}, new Location(this, pt.toVector3()));
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
@Override
|
||||
public Collection<BaseItemStack> 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
|
||||
|
||||
|
@ -3819,12 +3819,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
}
|
||||
if (containsAny) {
|
||||
changes++;
|
||||
TaskManager.taskManager().sync(new RunnableVal<Object>() {
|
||||
// TODO this seems to be broken?
|
||||
/* TaskManager.taskManager().sync(new RunnableVal<Object>() {
|
||||
@Override
|
||||
public void run(Object value) {
|
||||
regenerateChunk(cx, cz, biome, seed);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
if (changes != 0) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<BaseItemStack> 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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren