Skip to content

Commit 744c39d

Browse files
committed
feat: allow lobby sending on game end to be configured
1 parent 8ef77c3 commit 744c39d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: src/main/java/dev/emortal/minestom/gamesdk/config/GameSdkConfig.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param gameCreator a function that can be called to create a game instance
1313
*/
1414
public record GameSdkConfig(int minPlayers, int maxGames, int minTrackingInterval, int maxTrackingInterval,
15-
@NotNull GameCreator gameCreator) {
15+
boolean lobbyOnFinish, @NotNull GameCreator gameCreator) {
1616

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

3434
@NotNull GameCreatorStep maxTrackingInterval(int interval);
3535

36+
@NotNull GameCreatorStep lobbyOnFinish(boolean lobbyOnFinish);
37+
3638
@NotNull EndStep gameCreator(@NotNull GameCreator creator);
3739
}
3840

@@ -48,6 +50,7 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
4850
private int maxGames;
4951
private int minTrackingInterval = GameTracker.DEFAULT_MIN_UPDATE_INTERVAL;
5052
private int maxTrackingInterval = GameTracker.DEFAULT_MAX_UPDATE_INTERVAL;
53+
private boolean lobbyOnFinish = true;
5154
private GameCreator gameCreator;
5255

5356
@Override
@@ -74,6 +77,12 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
7477
return this;
7578
}
7679

80+
@Override
81+
public @NotNull GameCreatorStep lobbyOnFinish(boolean lobbyOnFinish) {
82+
this.lobbyOnFinish = lobbyOnFinish;
83+
return this;
84+
}
85+
7786
@Override
7887
public @NotNull EndStep gameCreator(@NotNull GameCreator creator) {
7988
this.gameCreator = creator;
@@ -83,7 +92,7 @@ private static final class BuilderImpl implements Builder, Builder.MaxGamesStep,
8392
@Override
8493
public @NotNull GameSdkConfig build() {
8594
return new GameSdkConfig(this.minPlayers, this.maxGames, this.minTrackingInterval, this.maxTrackingInterval,
86-
this.gameCreator);
95+
this.lobbyOnFinish, this.gameCreator);
8796
}
8897
}
8998
}

Diff for: src/main/java/dev/emortal/minestom/gamesdk/internal/GameManager.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ private void onGameFinish(@NotNull GameFinishedEvent event) {
9797
}
9898

9999
this.removeGame(game);
100-
KurushimiMinestomUtils.sendToLobby(game.getPlayers(), () -> this.cleanUpGame(game), () -> this.cleanUpGame(game));
100+
if (this.config.lobbyOnFinish()) {
101+
KurushimiMinestomUtils.sendToLobby(game.getPlayers(), () -> this.cleanUpGame(game), () -> this.cleanUpGame(game));
102+
} else {
103+
this.cleanUpGame(game);
104+
}
101105
}
102106

103107
private void cleanUpGame(@NotNull Game game) {

0 commit comments

Comments
 (0)