diff --git a/src/main/java/xyz/nucleoid/plasmid/Plasmid.java b/src/main/java/xyz/nucleoid/plasmid/Plasmid.java index d95e0519..02d08dc2 100644 --- a/src/main/java/xyz/nucleoid/plasmid/Plasmid.java +++ b/src/main/java/xyz/nucleoid/plasmid/Plasmid.java @@ -143,11 +143,7 @@ private void registerCallbacks() { ServerTickEvents.END_WORLD_TICK.register(world -> { var game = GameSpaceManager.get().byWorld(world); if (game != null) { - try { - game.getBehavior().propagatingInvoker(GameActivityEvents.TICK).onTick(); - } catch (Throwable t) { - game.closeWithError("An unexpected error occurred while ticking the game"); - } + game.tick(); } }); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java b/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java index 9c03d6dc..d5516a34 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java @@ -19,6 +19,7 @@ import xyz.nucleoid.plasmid.api.game.PlayerOffer; import xyz.nucleoid.plasmid.api.game.PlayerOfferResult; import xyz.nucleoid.plasmid.util.GlobalScheduler; +import xyz.nucleoid.plasmid.util.TickingScheduler; import java.util.Collection; import java.util.HashMap; @@ -44,6 +45,8 @@ public final class ManagedGameSpace implements GameSpace { private final GameSpaceStatistics statistics = new GameSpaceStatistics(); private final Map attachments = new HashMap<>(); + private final TickingScheduler scheduler = new TickingScheduler(); + ManagedGameSpace(MinecraftServer server, GameSpaceManager manager, GameSpaceMetadata metadata) { this.server = server; this.manager = manager; @@ -176,7 +179,7 @@ public boolean isClosed() { @Override public Scheduler getScheduler() { - return GlobalScheduler.get(); + return this.scheduler; } @Override @@ -259,4 +262,13 @@ void onAddWorld(RuntimeWorldHandle worldHandle) { void onRemoveWorld(RegistryKey dimension) { this.manager.removeDimensionFromGameSpace(this, dimension); } + + public void tick() { + try { + this.state.propagatingInvoker(GameActivityEvents.TICK).onTick(); + this.scheduler.tick(this.server); + } catch (Throwable t) { + this.closeWithError("An unexpected error occurred while ticking the game"); + } + } }