19
19
20
20
package org .screamingsandals .bedwars .game ;
21
21
22
+ import lombok .Getter ;
22
23
import lombok .RequiredArgsConstructor ;
23
24
import org .jetbrains .annotations .NotNull ;
25
+ import org .jetbrains .annotations .Nullable ;
26
+ import org .screamingsandals .bedwars .api .game .Game ;
24
27
import org .screamingsandals .bedwars .api .game .GameManager ;
28
+ import org .screamingsandals .bedwars .config .MainConfig ;
25
29
import org .screamingsandals .bedwars .utils .MiscUtils ;
26
30
import org .screamingsandals .bedwars .variants .VariantManagerImpl ;
27
31
import org .screamingsandals .lib .plugin .ServiceManager ;
32
+ import org .screamingsandals .lib .tasker .DefaultThreads ;
33
+ import org .screamingsandals .lib .tasker .Tasker ;
28
34
import org .screamingsandals .lib .utils .annotations .Service ;
29
35
import org .screamingsandals .lib .utils .annotations .ServiceDependencies ;
30
36
import org .screamingsandals .lib .utils .annotations .methods .OnPostEnable ;
@@ -49,6 +55,11 @@ public class GameManagerImpl implements GameManager {
49
55
private final LoggerWrapper logger ;
50
56
private final List <GameImpl > games = new LinkedList <>();
51
57
58
+ @ Getter
59
+ private @ Nullable Game preselectedGame ;
60
+ @ Getter
61
+ private boolean doGamePreselection ;
62
+
52
63
public static GameManagerImpl getInstance () {
53
64
return ServiceManager .get (GameManagerImpl .class );
54
65
}
@@ -141,14 +152,33 @@ public void onPostEnable() {
141
152
e .printStackTrace ();
142
153
}
143
154
}
155
+
156
+ if (
157
+ MainConfig .getInstance ().node ("bungee" , "enabled" ).getBoolean ()
158
+ && MainConfig .getInstance ().node ("bungee" , "random-game-selection" , "enabled" ).getBoolean ()
159
+ && MainConfig .getInstance ().node ("bungee" , "random-game-selection" , "preselect-games" ).getBoolean ()
160
+ ) {
161
+ Tasker .run (DefaultThreads .GLOBAL_THREAD , () -> {
162
+ preselectedGame = getGameWithHighestPlayers ().orElse (null );
163
+ doGamePreselection = true ;
164
+ });
165
+ }
144
166
}
145
167
146
168
@ OnPreDisable
147
169
public void onPreDisable () {
170
+ preselectedGame = null ;
171
+ doGamePreselection = false ;
148
172
games .forEach (GameImpl ::stop );
149
173
games .clear ();
150
174
}
151
175
176
+ public void reselectGame () {
177
+ if (doGamePreselection ) {
178
+ preselectedGame = getGameWithHighestPlayers ().orElse (null );
179
+ }
180
+ }
181
+
152
182
@ Override
153
183
public Optional <GameImpl > getGameWithHighestPlayers () {
154
184
return getGameWithHighestPlayers (false );
0 commit comments