Skip to content

Commit

Permalink
feat: expose modules to game server
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Sep 5, 2024
1 parent 884345c commit 95a6b5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,8 @@ public interface MinestomGameServer {

@NotNull GameProvider getGameProvider();

@NotNull ModuleManager getModuleManager();

interface Builder {

@NotNull Builder address(@NotNull String address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,17 +26,24 @@ 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
public @NotNull GameProvider getGameProvider() {
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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}

0 comments on commit 95a6b5c

Please sign in to comment.