1717
1818import club .moddedminecraft .polychat .bukkitclient .threads .ActivePlayerThread ;
1919import club .moddedminecraft .polychat .bukkitclient .threads .ReattachThread ;
20+ import org .bukkit .scheduler .BukkitScheduler ;
2021
2122public final class BukkitClient extends JavaPlugin implements Listener {
2223
@@ -28,6 +29,7 @@ public final class BukkitClient extends JavaPlugin implements Listener{
2829 public static String idJson = null ;
2930 public static String idJsonNoColor = null ;
3031 public static String serverIdText = null ;
32+ public static ArrayList <String > commands = new ArrayList <>();
3133
3234 public static void handleClientConnection () {
3335 try {
@@ -49,6 +51,13 @@ public static void sendGameMessage(String message) {
4951 Bukkit .broadcastMessage (message );
5052 }
5153
54+ public static void runCommand (String command ) { //Command Firer
55+ Bukkit .dispatchCommand (Bukkit .getConsoleSender (), command );
56+ }
57+ public static void addCommand (String command ) { //Holding place for commands
58+ commands .add (command );
59+ }
60+
5261 @ Override
5362 public void onEnable () {
5463 //TODO: check if the folder exists
@@ -61,9 +70,28 @@ public void onEnable() {
6170 new EventListener (this );
6271
6372 Runtime .getRuntime ().addShutdownHook (new Thread (this ::shutdownHook ));
73+ ServerInfoMessage infoMessage = new ServerInfoMessage (BukkitClient .properties .getProperty ("server_id" , "DEFAULT_ID" ),
74+ BukkitClient .properties .getProperty ("server_name" , "DEFAULT_NAME" ),
75+ BukkitClient .properties .getProperty ("server_address" , "DEFAULT_ADDRESS" ), BukkitClient .getMaxPlayers ());
76+ BukkitClient .sendMessage (infoMessage );
6477
6578 ServerStatusMessage onlineMsg = new ServerStatusMessage (properties .getProperty ("server_id" ), idJson , (short ) 1 );
6679 sendMessage (onlineMsg );
80+
81+ BukkitScheduler scheduler = getServer ().getScheduler ();
82+ scheduler .scheduleSyncRepeatingTask (this , new Runnable () { //Repeating task for listening for commands so they are ran on the right thread
83+ @ Override
84+ public void run () {
85+ if (commands .size () != 0 ) {
86+ int i = 0 ;
87+ while (i <commands .size ()){
88+ runCommand (commands .get (i ));
89+ i ++;
90+ }
91+ commands .clear ();
92+ }
93+ }
94+ }, 0L , 20L );
6795 }
6896
6997 @ Override
@@ -72,6 +100,8 @@ public void onDisable() {
72100 ServerStatusMessage offlineMsg = new ServerStatusMessage (properties .getProperty ("server_id" ), idJson , (short ) 2 );
73101 sendMessage (offlineMsg );
74102
103+ //TODO: Close Threads
104+
75105 }
76106
77107
0 commit comments