Skip to content

Commit

Permalink
Use Scheduler local to GameSpace instance, does not tick after closed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jun 8, 2024
1 parent 3d5c124 commit 0bdec2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/main/java/xyz/nucleoid/plasmid/Plasmid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,8 @@ public final class ManagedGameSpace implements GameSpace {
private final GameSpaceStatistics statistics = new GameSpaceStatistics();
private final Map<String, Object> attachments = new HashMap<>();

private final TickingScheduler scheduler = new TickingScheduler();

ManagedGameSpace(MinecraftServer server, GameSpaceManager manager, GameSpaceMetadata metadata) {
this.server = server;
this.manager = manager;
Expand Down Expand Up @@ -176,7 +179,7 @@ public boolean isClosed() {

@Override
public Scheduler getScheduler() {
return GlobalScheduler.get();
return this.scheduler;
}

@Override
Expand Down Expand Up @@ -259,4 +262,13 @@ void onAddWorld(RuntimeWorldHandle worldHandle) {
void onRemoveWorld(RegistryKey<World> 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");
}
}
}

0 comments on commit 0bdec2f

Please sign in to comment.