11package me .jaimemartz .lobbybalancer .section ;
22
3+ import lombok .Getter ;
4+ import lombok .Setter ;
35import me .jaimemartz .lobbybalancer .LobbyBalancer ;
46import me .jaimemartz .lobbybalancer .configuration .ConfigEntries ;
57import net .md_5 .bungee .api .config .ServerInfo ;
1315import java .util .regex .Pattern ;
1416
1517public class SectionManager {
16- private ServerSection principal ;
1718 private ScheduledTask updateTask ;
1819 private final LobbyBalancer plugin ;
19- private final Map <String , ServerSection > sectionStorage = new ConcurrentHashMap <>();
20- private final Map <ServerInfo , ServerSection > sectionServers = new ConcurrentHashMap <>();
20+ @ Getter @ Setter private ServerSection principal ;
21+ @ Getter private final Map <String , ServerSection > sections = new ConcurrentHashMap <>();
22+ @ Getter private final Map <ServerInfo , ServerSection > servers = new ConcurrentHashMap <>();
2123
2224 public SectionManager (LobbyBalancer plugin ) {
2325 this .plugin = plugin ;
@@ -32,27 +34,27 @@ public void load() throws RuntimeException {
3234 plugin .getLogger ().info (String .format ("Construction of section with name \" %s\" " , name ));
3335 Configuration section = sections .getSection (name );
3436 ServerSection object = new ServerSection (plugin , name , section );
35- sectionStorage .put (name , object );
37+ this . sections .put (name , object );
3638 });
3739
38- sectionStorage .forEach ((name , section ) -> {
40+ this . sections .forEach ((name , section ) -> {
3941 plugin .getLogger ().info (String .format ("Pre-Initialization of section with name \" %s\" " , name ));
4042 section .preInit ();
4143 });
4244
43- sectionStorage .forEach ((name , section ) -> {
45+ this . sections .forEach ((name , section ) -> {
4446 plugin .getLogger ().info (String .format ("Initialization of section with name \" %s\" " , name ));
4547 section .load ();
4648 });
4749
48- sectionStorage .forEach ((name , section ) -> {
50+ this . sections .forEach ((name , section ) -> {
4951 plugin .getLogger ().info (String .format ("Post-Initialization of section with name \" %s\" " , name ));
5052 section .postInit ();
5153 });
5254
5355 if (ConfigEntries .SERVERS_UPDATE .get ()) {
5456 updateTask = plugin .getProxy ().getScheduler ().schedule (plugin , () -> {
55- sectionStorage .forEach ((name , section ) -> {
57+ this . sections .forEach ((name , section ) -> {
5658 section .getConfiguration ().getStringList ("servers" ).forEach (entry -> {
5759 Pattern pattern = Pattern .compile (entry );
5860 plugin .getProxy ().getServers ().forEach ((key , value ) -> {
@@ -71,20 +73,20 @@ public void load() throws RuntimeException {
7173 }
7274
7375 long ending = System .currentTimeMillis () - starting ;
74- plugin .getLogger ().info (String .format ("A total of %s section(s) have been loaded in %sms" , sectionStorage .size (), ending ));
76+ plugin .getLogger ().info (String .format ("A total of %s section(s) have been loaded in %sms" , this . sections .size (), ending ));
7577 }
7678
7779 public void flush () {
7880 plugin .getLogger ().info ("Flushing section storage because of plugin shutdown" );
79- sectionStorage .forEach ((key , value ) -> {
81+ sections .forEach ((key , value ) -> {
8082 value .setValid (false );
8183
82- if (value .hasCommand () ) {
84+ if (value .getCommand () != null ) {
8385 SectionCommand command = value .getCommand ();
8486 plugin .getProxy ().getPluginManager ().unregisterCommand (command );
8587 }
8688
87- if (value .hasServer () ) {
89+ if (value .getServer () != null ) {
8890 ServerInfo server = value .getServer ();
8991 plugin .getProxy ().getServers ().remove (server .getName ());
9092 }
@@ -95,44 +97,34 @@ public void flush() {
9597 updateTask .cancel ();
9698 updateTask = null ;
9799 }
98- sectionStorage .clear ();
99- sectionServers .clear ();
100+ sections .clear ();
101+ servers .clear ();
100102 }
101103
102104 public void register (ServerInfo server , ServerSection section ) {
103- if (sectionServers .containsKey (server )) {
104- ServerSection other = sectionServers .get (server );
105+ if (servers .containsKey (server )) {
106+ ServerSection other = servers .get (server );
105107 throw new IllegalArgumentException (String .format ("The server \" %s\" is already in the section \" %s\" " , server .getName (), other .getName ()));
106108 }
107109
108110 plugin .getLogger ().info (String .format ("Registering server \" %s\" to section \" %s\" " , server .getName (), section .getName ()));
109- sectionServers .put (server , section );
111+ servers .put (server , section );
110112
111113 }
112114
113115 public ServerSection getByName (String name ) {
114- if (name == null ) return null ;
115- return sectionStorage .get (name );
116- }
117-
118- public ServerSection getByServer (ServerInfo server ) {
119- if (server == null ) return null ;
120- return sectionServers .get (server );
121- }
122-
123- public Map <String , ServerSection > getSections () {
124- return sectionStorage ;
125- }
116+ if (name == null ) {
117+ return null ;
118+ }
126119
127- public ServerSection getPrincipal () {
128- return principal ;
120+ return sections .get (name );
129121 }
130122
131- public void setPrincipal (ServerSection principal ) {
132- this .principal = principal ;
133- }
123+ public ServerSection getByServer (ServerInfo server ) {
124+ if (server == null ) {
125+ return null ;
126+ }
134127
135- public boolean hasPrincipal () {
136- return principal != null ;
128+ return servers .get (server );
137129 }
138130}
0 commit comments