kejonaMC / GeyserUpdater

Automatically update GeyserMC on spigot, velocity, and bungeecord servers.
GNU General Public License v3.0
39 stars 16 forks source link

Auto restart only when there are no players online #90

Open MrZomka opened 1 year ago

MrZomka commented 1 year ago

Auto restart is really handy, but it would've been better if it was possible for it to occur only when there are no players online to not cause any inconveniences :)

DokiDerg commented 1 year ago

as im surprised this hasnt been added, i will add code for the developer to easy go off of to hopefully get this feature faster

// this is assuming the method is run in your app class, add reference to the class if used externally

JavaPlugin plugin; // as a placeholder, replace with reference to your plugin class

// create an async thread
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new TimerTask() {
      @Override
      public void run() {
         while (plugin.getServer().getOnlinePlayers().size() > 0) { // Wait for the player count to reach 0
              try {
                  Thread.sleep(5000); // 5 second delay between online checks to not overwhelm the server
              }
              catch (InterruptedException e) {
                  e.printStackTrace(); // Error occurred with Thread.sleep
              }
          }

          plugin.getServer().shutdown(); // or replace with custom restart method
      }
});
dave9123 commented 1 year ago

@Konicai

dave9123 commented 1 year ago

Might have to add configuration to handle auto restart on no player online variable