Skip to content

Commit

Permalink
Refactor: encapsulate GameSpaceManager instance setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Dec 3, 2022
1 parent fd06e1a commit f007a85
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void openServer(MinecraftServer server) {
instance = new GameSpaceManager(server);
Stimuli.registerSelector(instance.listenerSelector);

GameSpaceManager.instance = instance;
GameSpaceManager.updateInstance(instance);
}

public static void startClosing() {
Expand All @@ -67,13 +67,17 @@ public static void startClosing() {
}

public static void closeServer() {
GameSpaceManager.instance = null;
GameSpaceManager.updateInstance(null);
}

public static GameSpaceManager get() {
return Preconditions.checkNotNull(instance, "GameSpaceManager not yet initialized");
}

private static void updateInstance(@Nullable GameSpaceManager instance) {
GameSpaceManager.instance = instance;
}

public CompletableFuture<ManagedGameSpace> open(GameConfig<?> config) {
return CompletableFuture.supplyAsync(
() -> config.openProcedure(this.server),
Expand Down

0 comments on commit f007a85

Please sign in to comment.