88import net .md_5 .bungee .api .config .ServerInfo ;
99import net .md_5 .bungee .api .connection .ProxiedPlayer ;
1010import net .md_5 .bungee .api .connection .Server ;
11- import net .md_5 .bungee .api .scheduler .ScheduledTask ;
1211
1312import java .util .*;
1413import java .util .concurrent .atomic .AtomicBoolean ;
1817public class SectionManager {
1918 private final PlayerBalancer plugin ;
2019 private final BalancerProps props ;
21- private ScheduledTask updateTask ;
2220 private ServerSection principal ;
2321
2422 private final Map <String , ServerSection > sections = Collections .synchronizedMap (new HashMap <>());
@@ -64,11 +62,6 @@ public void flush() {
6462 }
6563 });
6664
67- if (updateTask != null ) {
68- updateTask .cancel ();
69- updateTask = null ;
70- }
71-
7265 principal = null ;
7366 sections .clear ();
7467 servers .clear ();
@@ -122,9 +115,9 @@ public ServerSection getByPlayer(ProxiedPlayer player) {
122115 private final Stage [] stages = {
123116 new SectionStage ("Constructing sections" ) {
124117 @ Override
125- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
126- ServerSection object = new ServerSection (name , props );
127- sections .put (name , object );
118+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
119+ ServerSection object = new ServerSection (sectionName , sectionProps );
120+ sections .put (sectionName , object );
128121 }
129122 },
130123 new GlobalStage ("Processing principal section" ) {
@@ -141,9 +134,9 @@ public void execute() {
141134 },
142135 new SectionStage ("Processing parents" ) {
143136 @ Override
144- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
145- if (props .getParentName () != null ) {
146- ServerSection parent = getByName (props .getParentName ());
137+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
138+ if (sectionProps .getParentName () != null ) {
139+ ServerSection parent = getByName (sectionProps .getParentName ());
147140 if (principal .equals (section ) && parent == null ) {
148141 throw new IllegalArgumentException (String .format (
149142 "The section \" %s\" has an invalid parent set" ,
@@ -157,7 +150,7 @@ public void execute(String name, SectionProps props, ServerSection section) thro
157150 },
158151 new SectionStage ("Validating parents" ) {
159152 @ Override
160- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
153+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
161154 ServerSection parent = section .getParent ();
162155 if (parent != null && parent .getParent () == section ) {
163156 throw new IllegalStateException (String .format (
@@ -170,8 +163,8 @@ public void execute(String name, SectionProps props, ServerSection section) thro
170163 },
171164 new SectionStage ("Validating providers" ) {
172165 @ Override
173- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
174- if (props .getProvider () == null ) {
166+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
167+ if (sectionProps .getProvider () == null ) {
175168 ServerSection current = section .getParent ();
176169 if (current != null ) {
177170 while (current .getExplicitProvider () == null ) {
@@ -193,20 +186,20 @@ public void execute(String name, SectionProps props, ServerSection section) thro
193186 },
194187 new SectionStage ("Calculating positions" ) {
195188 @ Override
196- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
189+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
197190 section .setPosition (calculatePosition (section ));
198191 }
199192 },
200193 new SectionStage ("Resolving servers" ) {
201194 @ Override
202- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
195+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
203196 section .setServers (calculateServers (section ));
204197 }
205198 },
206199 new SectionStage ("Section server processing" ) {
207200 @ Override
208- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
209- if (props .getServerName () != null ) {
201+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
202+ if (sectionProps .getServerName () != null ) {
210203 FakeServer server = new FakeServer (section );
211204 section .setServer (server );
212205 plugin .getSectionManager ().register (server , section );
@@ -217,20 +210,20 @@ public void execute(String name, SectionProps props, ServerSection section) thro
217210 },
218211 new SectionStage ("Section command processing" ) {
219212 @ Override
220- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
221- if (props .getCommand () != null ) {
222- SectionCommand command = new SectionCommand (plugin , props .getCommand (), section );
213+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
214+ if (sectionProps .getCommand () != null ) {
215+ SectionCommand command = new SectionCommand (plugin , sectionProps .getCommand (), section );
223216 section .setCommand (command );
224217 plugin .getProxy ().getPluginManager ().registerCommand (plugin , command );
225218 }
226219 }
227220 },
228221 new SectionStage ("Finishing loading sections" ) {
229222 @ Override
230- public void execute (String name , SectionProps props , ServerSection section ) throws RuntimeException {
223+ public void execute (String sectionName , SectionProps sectionProps , ServerSection section ) throws RuntimeException {
231224 section .setValid (true );
232225 }
233- }
226+ },
234227 };
235228
236229 public Set <ServerInfo > calculateServers (ServerSection section ) {
@@ -345,8 +338,8 @@ private SectionStage(String title) {
345338 }
346339
347340 public abstract void execute (
348- String name ,
349- SectionProps props ,
341+ String sectionName ,
342+ SectionProps sectionProps ,
350343 ServerSection section
351344 ) throws RuntimeException ;
352345 }
0 commit comments