@@ -28,6 +28,7 @@ public final class BukkitClient extends JavaPlugin implements Listener{
2828 public static ActivePlayerThread playerThread ;
2929 public static String idJson = null ;
3030 public static String idJsonNoColor = null ;
31+ public static boolean reattachKill = false ;
3132 public static String serverIdText = null ;
3233 public static ArrayList <String > commands = new ArrayList <>();
3334
@@ -63,17 +64,23 @@ public void onEnable() {
6364 //TODO: check if the folder exists
6465 handleConfiguration (this .getDataFolder ());
6566 handlePrefix ();
66- reattachThread = new ReattachThread (5000 );
6767
68+ reattachThread = new ReattachThread (5000 );
6869 playerThread = new ActivePlayerThread (30000 , properties .getProperty ("server_id" , "DEFAULT_ID" ));
70+
6971 handleClientConnection ();
70-
72+
7173 new EventListener (this );
7274
7375 Runtime .getRuntime ().addShutdownHook (new Thread (this ::shutdownHook ));
74- ServerInfoMessage infoMessage = new ServerInfoMessage (BukkitClient .properties .getProperty ("server_id" , "DEFAULT_ID" ),
76+
77+ ServerInfoMessage infoMessage = new ServerInfoMessage (
78+ BukkitClient .properties .getProperty ("server_id" , "DEFAULT_ID" ),
7579 BukkitClient .properties .getProperty ("server_name" , "DEFAULT_NAME" ),
76- BukkitClient .properties .getProperty ("server_address" , "DEFAULT_ADDRESS" ), BukkitClient .getMaxPlayers ());
80+ BukkitClient .properties .getProperty ("server_address" , "DEFAULT_ADDRESS" ),
81+ BukkitClient .getMaxPlayers ()
82+ );
83+
7784 BukkitClient .sendMessage (infoMessage );
7885
7986 ServerStatusMessage onlineMsg = new ServerStatusMessage (properties .getProperty ("server_id" ), idJson , (short ) 1 );
@@ -93,13 +100,18 @@ public void run() {
93100 }
94101 }
95102 }, 0L , 20L );
103+ if (!reattachKill ) { //only start it on a fresh start, not on a reload
104+ reattachThread .start ();//actually start the thread at the end so the main thread is running already
105+ }else {
96106
97- reattachThread . start (); //actually start the thread at the end so the main thread is running already
107+ }
98108 }
99109
100110 @ Override
101111 public void onDisable () {
102112 shutdownClean = true ;
113+ reattachKill = true ;
114+
103115 ServerStatusMessage offlineMsg = new ServerStatusMessage (properties .getProperty ("server_id" ), idJson , (short ) 2 );
104116 sendMessage (offlineMsg );
105117
@@ -117,8 +129,6 @@ public void onDisable() {
117129
118130
119131 public void shutdownHook () {
120- reattachThread .interrupt ();
121- playerThread .interrupt ();
122132 //Sends either crashed or offline depending on if shutdown happened cleanly
123133 if (!shutdownClean ) {
124134 ServerStatusMessage crashMsg = new ServerStatusMessage (properties .getProperty ("server_id" ), idJson , (short ) 3 );
@@ -129,6 +139,7 @@ public void shutdownHook() {
129139 Thread .sleep (1000 );
130140 } catch (InterruptedException ignored ) {
131141 }
142+ messageBus .stop ();
132143 }
133144
134145 public static ArrayList <String > getOnlinePlayersNames () { //Might have to fix return type
0 commit comments