@@ -50,6 +50,7 @@ public class SculkPrisonActivePhase implements PlayerAttackEntityEvent, GameActi
50
50
51
51
private int lockTime ;
52
52
private int surviveTime ;
53
+ private int ticksUntilClose = -1 ;
53
54
54
55
public SculkPrisonActivePhase (GameSpace gameSpace , ServerWorld world , SculkPrisonMap map , SculkPrisonConfig config , List <ServerPlayerEntity > players , GlobalWidgets widgets ) {
55
56
this .world = world ;
@@ -104,7 +105,7 @@ public static void open(GameSpace gameSpace, ServerWorld world, SculkPrisonMap m
104
105
// Listeners
105
106
@ Override
106
107
public ActionResult onAttackEntity (ServerPlayerEntity attacker , Hand hand , Entity attacked , EntityHitResult hitResult ) {
107
- if (attacker .equals (this .warden ) && attacked instanceof ServerPlayerEntity ) {
108
+ if (! this . isGameEnding () && attacker .equals (this .warden ) && attacked instanceof ServerPlayerEntity ) {
108
109
this .eliminate ((ServerPlayerEntity ) attacked , Text .translatable ("text.sculkprison.eliminated.warden" , attacked .getDisplayName (), attacker .getDisplayName ()), true );
109
110
}
110
111
return ActionResult .FAIL ;
@@ -125,6 +126,15 @@ public void onEnable() {
125
126
126
127
@ Override
127
128
public void onTick () {
129
+ // Decrease ticks until game end to zero
130
+ if (this .isGameEnding ()) {
131
+ if (this .ticksUntilClose == 0 ) {
132
+ this .gameSpace .close (GameCloseReason .FINISHED );
133
+ }
134
+ this .ticksUntilClose -= 1 ;
135
+ return ;
136
+ }
137
+
128
138
this .lockTime -= 1 ;
129
139
if (this .lockTime < 0 ) {
130
140
this .surviveTime -= 1 ;
@@ -165,7 +175,6 @@ public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) {
165
175
@ Override
166
176
public void onRemovePlayer (ServerPlayerEntity player ) {
167
177
this .eliminate (player , true );
168
- this .players .remove (player );
169
178
}
170
179
171
180
// Utilities
@@ -189,6 +198,8 @@ private void setSpectator(ServerPlayerEntity player) {
189
198
* @param remove whether to remove the player from {@link SculkPrisonActivePhase#players}
190
199
*/
191
200
private void eliminate (ServerPlayerEntity player , Text message , boolean remove ) {
201
+ if (this .isGameEnding ()) return ;
202
+
192
203
this .gameSpace .getPlayers ().sendMessage (message );
193
204
194
205
if (remove ) {
@@ -214,12 +225,16 @@ private void eliminate(ServerPlayerEntity player, boolean remove) {
214
225
*/
215
226
private void endWithWinner (WinTeam team ) {
216
227
this .gameSpace .getPlayers ().sendMessage (team .getWinMessage ());
217
- this .gameSpace . close ( GameCloseReason . FINISHED );
228
+ this .endGame ( );
218
229
}
219
230
220
231
private void endWithNoWinners () {
221
232
this .gameSpace .getPlayers ().sendMessage (Text .translatable ("text.sculkprison.no_winners" ).formatted (Formatting .RED ));
222
- this .gameSpace .close (GameCloseReason .FINISHED );
233
+ this .endGame ();
234
+ }
235
+
236
+ private void endGame () {
237
+ this .ticksUntilClose = this .config .getTicksUntilClose ().get (this .world .getRandom ());
223
238
}
224
239
225
240
/**
@@ -245,6 +260,10 @@ public int getLockTime() {
245
260
return this .lockTime ;
246
261
}
247
262
263
+ private boolean isGameEnding () {
264
+ return this .ticksUntilClose >= 0 ;
265
+ }
266
+
248
267
/**
249
268
* Spawns a given player within the map.
250
269
* @param warden whether to use the {@linkplain SculkPrisonMap#WARDEN_SPAWN warden spawn} instead of the {@linkplain SculkPrisonMap#SPAWN default spawn}
0 commit comments