diff --git a/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServer.java b/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServer.java index 0aff151..73969fa 100644 --- a/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServer.java +++ b/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServer.java @@ -2,6 +2,7 @@ import dev.emortal.api.modules.LoadableModule; import dev.emortal.api.modules.Module; +import dev.emortal.api.modules.ModuleManager; import dev.emortal.minestom.gamesdk.config.GameSdkConfig; import dev.emortal.minestom.gamesdk.game.GameProvider; import org.jetbrains.annotations.NotNull; @@ -21,6 +22,8 @@ public interface MinestomGameServer { @NotNull GameProvider getGameProvider(); + @NotNull ModuleManager getModuleManager(); + interface Builder { @NotNull Builder address(@NotNull String address); diff --git a/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServerImpl.java b/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServerImpl.java index 68d4e67..42ec581 100644 --- a/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServerImpl.java +++ b/src/main/java/dev/emortal/minestom/gamesdk/MinestomGameServerImpl.java @@ -2,6 +2,7 @@ import dev.emortal.api.modules.LoadableModule; import dev.emortal.api.modules.Module; +import dev.emortal.api.modules.ModuleManager; import dev.emortal.api.modules.ModuleProvider; import dev.emortal.minestom.core.Environment; import dev.emortal.minestom.core.MinestomServer; @@ -25,10 +26,12 @@ final class MinestomGameServerImpl implements MinestomGameServer { private static final Logger LOGGER = LoggerFactory.getLogger(MinestomGameServerImpl.class); static final boolean TEST_MODE = !Environment.isProduction() && Boolean.parseBoolean(System.getenv("GAME_SDK_TEST_MODE")); - private final GameProvider gameProvider; + private final @NotNull GameProvider gameProvider; + private final @NotNull MinestomServer server; - private MinestomGameServerImpl(@NotNull GameProvider gameProvider) { + private MinestomGameServerImpl(@NotNull GameProvider gameProvider, @NotNull MinestomServer server) { this.gameProvider = gameProvider; + this.server = server; } @Override @@ -36,6 +39,11 @@ private MinestomGameServerImpl(@NotNull GameProvider gameProvider) { return this.gameProvider; } + @Override + public @NotNull ModuleManager getModuleManager() { + return this.server.getModuleManager(); + } + static final class BuilderImpl implements Builder, Builder.EndStep { private final MinestomServer.Builder serverBuilder = MinestomServer.builder(); @@ -80,12 +88,12 @@ static final class BuilderImpl implements Builder, Builder.EndStep { @Override public @NotNull MinestomGameServerImpl build() { MinestomServer server = this.serverBuilder.build(); - MinestomGameServerImpl gameServer = initialize(server.getModuleManager(), this.configSupplier.get()); + MinestomGameServerImpl gameServer = initialize(server.getModuleManager(), this.configSupplier.get(), server); server.start(); return gameServer; } - private static @NotNull MinestomGameServerImpl initialize(@NotNull ModuleProvider moduleProvider, @NotNull GameSdkConfig config) { + private static @NotNull MinestomGameServerImpl initialize(@NotNull ModuleProvider moduleProvider, @NotNull GameSdkConfig config, @NotNull MinestomServer server) { LOGGER.info("Initializing Game SDK (test mode: {}, config: {})", TEST_MODE, config); MessagingModule messaging = moduleProvider.getModule(MessagingModule.class); @@ -106,7 +114,7 @@ static final class BuilderImpl implements Builder, Builder.EndStep { MinecraftServer.getCommandManager().register(new GameSdkCommand(gameManager)); - return new MinestomGameServerImpl(gameManager); + return new MinestomGameServerImpl(gameManager, server); } } }