44import com .jaimemartz .playerbalancer .commands .FallbackCommand ;
55import com .jaimemartz .playerbalancer .commands .MainCommand ;
66import com .jaimemartz .playerbalancer .commands .ManageCommand ;
7- import com .jaimemartz .playerbalancer .connection .ServerAssignRegistry ;
87import com .jaimemartz .playerbalancer .listener .*;
98import com .jaimemartz .playerbalancer .manager .NetworkManager ;
109import com .jaimemartz .playerbalancer .manager .PasteHelper ;
1110import com .jaimemartz .playerbalancer .manager .PlayerLocker ;
1211import com .jaimemartz .playerbalancer .ping .StatusManager ;
1312import com .jaimemartz .playerbalancer .section .SectionManager ;
14- import com .jaimemartz .playerbalancer .settings .MainSettings ;
13+ import com .jaimemartz .playerbalancer .settings .SettingsHolder ;
1514import net .md_5 .bungee .api .plugin .Command ;
1615import net .md_5 .bungee .api .plugin .Listener ;
1716import net .md_5 .bungee .api .plugin .Plugin ;
3130public class PlayerBalancer extends Plugin {
3231 private boolean failed = false ;
3332 private StatusManager statusManager ;
34- private MainSettings mainSettings ;
33+ private SettingsHolder mainSettings ;
3534 private ConfigurationLoader <CommentedConfigurationNode > loader ;
3635 private SectionManager sectionManager ;
3736 private NetworkManager networkManager ;
@@ -63,11 +62,11 @@ private void enable() {
6362 CommentedConfigurationNode node = loader .load ();
6463
6564 if (!file .exists ()) {
66- mainSettings = new MainSettings () .__defaults ();
67- node .setValue (TypeToken .of (MainSettings .class ), mainSettings );
65+ mainSettings = new SettingsHolder (); // .__defaults(); todo load defaults from default config
66+ node .setValue (TypeToken .of (SettingsHolder .class ), mainSettings );
6867 loader .save (node );
6968 } else {
70- mainSettings = node .getValue (TypeToken .of (MainSettings .class ));
69+ mainSettings = node .getValue (TypeToken .of (SettingsHolder .class ));
7170 }
7271 } catch (Exception e ) {
7372 e .printStackTrace ();
@@ -76,7 +75,7 @@ private void enable() {
7675 mainCommand = new MainCommand (this );
7776 getProxy ().getPluginManager ().registerCommand (this , mainCommand );
7877
79- if (mainSettings .getGeneralProps ().isActive ()) {
78+ if (mainSettings .getGeneralProps ().isEnabled ()) {
8079 if (mainSettings .getGeneralProps ().isSilent ()) {
8180 getLogger ().setLevel (Level .WARNING );
8281 }
@@ -99,11 +98,11 @@ private void enable() {
9998 sectionManager .load ();
10099
101100 statusManager = new StatusManager (this );
102- if (mainSettings .getServerCheckerProps ().isActive ()) {
101+ if (mainSettings .getServerCheckerProps ().isEnabled ()) {
103102 statusManager .start ();
104103 }
105104
106- if (mainSettings .getFallbackCommandProps ().isActive ()) {
105+ if (mainSettings .getFallbackCommandProps ().isEnabled ()) {
107106 fallbackCommand = new FallbackCommand (this , mainSettings .getFallbackCommandProps ().getCommand ());
108107 getProxy ().getPluginManager ().registerCommand (this , fallbackCommand );
109108 }
@@ -123,7 +122,7 @@ private void enable() {
123122
124123 PasteHelper .reset ();
125124
126- if (mainSettings .getKickHandlerProps ().isActive ()) {
125+ if (mainSettings .getKickHandlerProps ().isEnabled ()) {
127126 kickListener = new ServerKickListener (this );
128127 getProxy ().getPluginManager ().registerListener (this , kickListener );
129128 }
@@ -151,7 +150,7 @@ private void disable() {
151150 getProxy ().getPluginManager ().unregisterCommand (mainCommand );
152151 mainCommand = null ;
153152
154- if (mainSettings .getGeneralProps ().isActive ()) {
153+ if (mainSettings .getGeneralProps ().isEnabled ()) {
155154 //Do not try to do anything if the plugin has not loaded correctly
156155 if (failed ) return ;
157156
@@ -160,15 +159,20 @@ private void disable() {
160159 reloadListener = null ;
161160 }
162161
163- if (mainSettings .getServerCheckerProps ().isActive ()) {
162+ if (mainSettings .getServerCheckerProps ().isEnabled ()) {
164163 statusManager .stop ();
165164 }
166165
167- if (mainSettings .getFallbackCommandProps ().isActive ()) {
166+ if (mainSettings .getFallbackCommandProps ().isEnabled ()) {
168167 getProxy ().getPluginManager ().unregisterCommand (fallbackCommand );
169168 fallbackCommand = null ;
170169 }
171170
171+ if (mainSettings .getKickHandlerProps ().isEnabled ()) {
172+ getProxy ().getPluginManager ().unregisterListener (kickListener );
173+ kickListener = null ;
174+ }
175+
172176 getProxy ().getPluginManager ().unregisterListener (connectListener );
173177 connectListener = null ;
174178
@@ -178,16 +182,13 @@ private void disable() {
178182 getProxy ().getPluginManager ().unregisterCommand (manageCommand );
179183 manageCommand = null ;
180184
181- if (mainSettings .getKickHandlerProps ().isActive ()) {
182- getProxy ().getPluginManager ().unregisterListener (kickListener );
183- kickListener = null ;
184- }
185-
186185 sectionManager .flush ();
187186
187+ /*
188188 if (mainSettings.getGeneralProps().isAssignTargets()) {
189189 ServerAssignRegistry.getTable().clear();
190190 }
191+ */
191192 }
192193
193194 PlayerLocker .flush ();
@@ -207,7 +208,7 @@ public boolean reloadPlugin() {
207208 return !failed ;
208209 }
209210
210- public MainSettings getSettings () {
211+ public SettingsHolder getSettings () {
211212 return mainSettings ;
212213 }
213214
0 commit comments