Skip to content

Commit

Permalink
Delay scheduled tasks so they don't end up being excuted immediately.…
Browse files Browse the repository at this point in the history
… Might help prevent crashes like #95
  • Loading branch information
Sollace committed Jan 28, 2023
1 parent cdb06be commit 8a13b02
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/minelittlepony/unicopia/AwaitTickQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;

public class AwaitTickQueue {
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
public interface AwaitTickQueue {
static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
if (reference instanceof ServerWorld serverWorld) {
CompletableFuture.runAsync(() -> {
task.accept(serverWorld);
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, serverWorld.getServer()));
}
}

public static void scheduleTask(World reference, Consumer<World> task) {
static void scheduleTask(World reference, Consumer<World> task) {
if (reference instanceof ServerWorld serverWorld) {
CompletableFuture.runAsync(() -> {
task.accept(serverWorld);
}, serverWorld.getServer());
}, CompletableFuture.delayedExecutor(1, TimeUnit.MILLISECONDS, serverWorld.getServer()));
}
}
}

0 comments on commit 8a13b02

Please sign in to comment.