Skip to content

Commit

Permalink
feat: allow lobby sending on game end to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Mar 10, 2024
1 parent 8ef77c3 commit 744c39d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param gameCreator a function that can be called to create a game instance
*/
public record GameSdkConfig(int minPlayers, int maxGames, int minTrackingInterval, int maxTrackingInterval,
@NotNull GameCreator gameCreator) {
boolean lobbyOnFinish, @NotNull GameCreator gameCreator) {

public static @NotNull Builder builder() {
return new BuilderImpl();
Expand All @@ -33,6 +33,8 @@ interface GameCreatorStep {

@NotNull GameCreatorStep maxTrackingInterval(int interval);

@NotNull GameCreatorStep lobbyOnFinish(boolean lobbyOnFinish);

@NotNull EndStep gameCreator(@NotNull GameCreator creator);
}

Expand All @@ -48,6 +50,7 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
private int maxGames;
private int minTrackingInterval = GameTracker.DEFAULT_MIN_UPDATE_INTERVAL;
private int maxTrackingInterval = GameTracker.DEFAULT_MAX_UPDATE_INTERVAL;
private boolean lobbyOnFinish = true;
private GameCreator gameCreator;

@Override
Expand All @@ -74,6 +77,12 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
return this;
}

@Override
public @NotNull GameCreatorStep lobbyOnFinish(boolean lobbyOnFinish) {
this.lobbyOnFinish = lobbyOnFinish;
return this;
}

@Override
public @NotNull EndStep gameCreator(@NotNull GameCreator creator) {
this.gameCreator = creator;
Expand All @@ -83,7 +92,7 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
@Override
public @NotNull GameSdkConfig build() {
return new GameSdkConfig(this.minPlayers, this.maxGames, this.minTrackingInterval, this.maxTrackingInterval,
this.gameCreator);
this.lobbyOnFinish, this.gameCreator);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ private void onGameFinish(@NotNull GameFinishedEvent event) {
}

this.removeGame(game);
KurushimiMinestomUtils.sendToLobby(game.getPlayers(), () -> this.cleanUpGame(game), () -> this.cleanUpGame(game));
if (this.config.lobbyOnFinish()) {
KurushimiMinestomUtils.sendToLobby(game.getPlayers(), () -> this.cleanUpGame(game), () -> this.cleanUpGame(game));
} else {
this.cleanUpGame(game);
}
}

private void cleanUpGame(@NotNull Game game) {
Expand Down

0 comments on commit 744c39d

Please sign in to comment.