33import com .google .common .base .Preconditions ;
44import com .jaimemartz .playerbalancer .PlayerBalancer ;
55import com .jaimemartz .playerbalancer .settings .props .features .BalancerProps ;
6+ import com .jaimemartz .playerbalancer .settings .props .shared .SectionProps ;
7+ import com .jaimemartz .playerbalancer .utils .FakeServer ;
68import com .jaimemartz .playerbalancer .utils .FixedAdapter ;
79import net .md_5 .bungee .api .config .ServerInfo ;
810import net .md_5 .bungee .api .connection .ProxiedPlayer ;
911import net .md_5 .bungee .api .connection .Server ;
1012import net .md_5 .bungee .api .scheduler .ScheduledTask ;
1113
12- import java .net .InetSocketAddress ;
1314import java .util .*;
1415import java .util .concurrent .atomic .AtomicBoolean ;
1516import java .util .regex .Matcher ;
@@ -29,7 +30,7 @@ public SectionManager(PlayerBalancer plugin) {
2930 }
3031
3132 public void load () throws RuntimeException {
32- plugin .getLogger ().info ("Loading sections from the config , this may take a while..." );
33+ plugin .getLogger ().info ("Executing section initialization stages , this may take a while..." );
3334 long starting = System .currentTimeMillis ();
3435
3536 props .getSectionProps ().forEach ((name , prop ) -> {
@@ -119,6 +120,21 @@ public ServerSection getByPlayer(ProxiedPlayer player) {
119120 return getByServer (server .getInfo ());
120121 }
121122
123+ private final Stage [] stages = {
124+ new Stage ("Creation" ) {
125+ @ Override
126+ public void execute (SectionProps props , ServerSection section ) throws RuntimeException {
127+
128+ }
129+ },
130+ new Stage ("" ) {
131+ @ Override
132+ public void execute (SectionProps props , ServerSection section ) throws RuntimeException {
133+
134+ }
135+ }
136+ };
137+
122138 public void processSection (String sectionName , ServerSection section ) throws RuntimeException {
123139 plugin .getLogger ().info (String .format ("Loading section with name \" %s\" " , sectionName ));
124140
@@ -143,29 +159,14 @@ public void processSection(String sectionName, ServerSection section) throws Run
143159 Set <ServerInfo > servers = calculateServers (section );
144160 section .getServers ().addAll (servers );
145161
146- //TODO move this to other stage
147- if (section .getProps ().getProvider () != null ) {
148- section .setInherited (false );
149- } else {
150- section .setInherited (true );
151-
152- if (section .getImplicitProvider () != null ) {
153-
154- } else {
155- throw new IllegalStateException (String .format ("The section \" %s\" does not have a provider" , sectionName ));
156- }
157- }
162+ //TODO Load sections
158163
159164 section .setPosition (calculatePosition (section ));
160165
161166 Optional .ofNullable (section .getProps ().getServerName ()).ifPresent (serverName -> {
162- int port = (int ) Math .floor (Math .random () * (0xFFFF + 1 )); //Get a random valid port for our fake server
163- ServerInfo server = plugin .getProxy ().constructServerInfo (
164- "@" + serverName ,
165- new InetSocketAddress ("0.0.0.0" , port ),
166- String .format ("Server of Section %s" , sectionName ),
167- false );
167+ FakeServer server = new FakeServer (section );
168168 section .setServer (server );
169+
169170 plugin .getSectionManager ().register (server , section );
170171 FixedAdapter .getFakeServers ().put (server .getName (), server );
171172 plugin .getProxy ().getServers ().put (server .getName (), server );
@@ -174,6 +175,7 @@ public void processSection(String sectionName, ServerSection section) throws Run
174175 Optional .ofNullable (section .getProps ().getCommand ()).ifPresent (props -> {
175176 SectionCommand command = new SectionCommand (plugin , props , section );
176177 section .setCommand (command );
178+
177179 plugin .getProxy ().getPluginManager ().registerCommand (plugin , command );
178180 });
179181
@@ -258,7 +260,7 @@ public Optional<ServerSection> getBind(Map<String, String> rules, ServerSection
258260 return Optional .ofNullable (res );
259261 }
260262
261- //maybe store this as a variable?
263+ //todo maybe store this as a variable?
262264 public ServerSection getPrincipal () {
263265 return getByName (props .getPrincipalSectionName ());
264266 }
@@ -270,4 +272,21 @@ public boolean isPrincipal(ServerSection section) {
270272 public Map <String , ServerSection > getSections () {
271273 return sections ;
272274 }
275+
276+ private abstract static class Stage {
277+ private final String title ;
278+
279+ public Stage (String title ) {
280+ this .title = title ;
281+ }
282+
283+ public String getTitle () {
284+ return title ;a
285+ }
286+
287+ public abstract void execute (
288+ SectionProps props ,
289+ ServerSection section
290+ ) throws RuntimeException ;
291+ }
273292}
0 commit comments