@@ -41,7 +41,7 @@ public class BlockLobbersActivePhase implements BlockBreakEvent, GameActivityEve
4141 private final Set <PlayerEntry > players ;
4242 private final WinManager winManager ;
4343
44- private boolean closing ;
44+ private int ticksUntilClose = - 1 ;
4545
4646 public BlockLobbersActivePhase (GameSpace gameSpace , ServerWorld world , BlockLobbersMap map , BlockLobbersConfig config ) {
4747 this .gameSpace = gameSpace ;
@@ -106,6 +106,17 @@ public void onEnable() {
106106
107107 @ Override
108108 public void onTick () {
109+ // Decrease ticks until game end to zero
110+ if (this .isGameEnding ()) {
111+ if (this .ticksUntilClose == 0 ) {
112+ this .gameSpace .close (GameCloseReason .FINISHED );
113+ } else {
114+ this .ticksUntilClose -= 1 ;
115+ }
116+
117+ return ;
118+ }
119+
109120 Iterator <PlayerEntry > playerIterator = this .players .iterator ();
110121 while (playerIterator .hasNext ()) {
111122 PlayerEntry entry = playerIterator .next ();
@@ -116,8 +127,7 @@ public void onTick() {
116127
117128 // Attempt to determine a winner
118129 if (this .winManager .checkForWinner ()) {
119- this .closing = true ;
120- gameSpace .close (GameCloseReason .FINISHED );
130+ this .endGame ();
121131 }
122132 }
123133
@@ -207,7 +217,7 @@ private void setSpectator(ServerPlayerEntity player) {
207217 }
208218
209219 private boolean eliminate (PlayerEntry entry , String suffix , boolean remove ) {
210- if (this .closing ) return false ;
220+ if (this .isGameEnding () ) return false ;
211221
212222 Text message = entry .getEliminatedText (suffix );
213223 for (ServerPlayerEntity player : this .gameSpace .getPlayers ()) {
@@ -225,4 +235,12 @@ private boolean eliminate(PlayerEntry entry, String suffix, boolean remove) {
225235 public boolean eliminate (PlayerEntry entry , boolean remove ) {
226236 return this .eliminate (entry , "" , remove );
227237 }
238+
239+ private void endGame () {
240+ this .ticksUntilClose = this .config .getTicksUntilClose ().get (this .world .getRandom ());
241+ }
242+
243+ private boolean isGameEnding () {
244+ return this .ticksUntilClose >= 0 ;
245+ }
228246}
0 commit comments