Solved Restart by jar file

Discussion in 'Plugin Development' started by DarkenCake, Jul 18, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    DarkenCake

    I need to make util that allows me to create wipe by easy way, so, I delete playerdata folder by folder.delete();
    but I need else to restart my server after wipe will done, so there it is:
    Show Spoiler

    Code:
          public static void restart()
          {
            restart(new File(configManager.restartScript));
          }
          public static void restart(File script)
          {
            AsyncCatcher.enabled = false;
            try
            {
              if (script.isFile())
              {
                System.out.println("[WipeUtil] Trying to restart with " + configManager.restartScript);
               
                WatchdogThread.doStop();
                for (Player ps : Bukkit.getOnlinePlayers()) {
                    ps.kickPlayer(configManager.messageReboot);
                }
                try
                {
                  Thread.sleep(100L);
                }
                catch (InterruptedException ex) {}
                MinecraftServer.getServer().getServerConnection().b();
                try
                {
                  Thread.sleep(100L);
                }
                catch (InterruptedException ex) {}
                try
                {
                  MinecraftServer.getServer().stop();
                }
                catch (Throwable t) {}
                Object shutdownHook = new Thread()
                {
                  private Object val$script;
    
                public void run()
                  {
                    try
                    {
                      String os = System.getProperty("os.name").toLowerCase();
                      if (os.contains("win")) {
                        Runtime.getRuntime().exec("cmd /c start " + ((File) this.val$script).getPath());
                      } else {
                        Runtime.getRuntime().exec(new String[] { "sh", ((File) this.val$script)
                       
                          .getPath() });
                      }
                    }
                    catch (Exception e)
                    {
                      e.printStackTrace();
                    }
                  }
                };
                ((Thread)shutdownHook).setDaemon(true);
                Runtime.getRuntime().addShutdownHook((Thread)shutdownHook);
              }else {
                System.out.println("[WipeUtil] Startup script '" + configManager.restartScript + "' not found! Attempting to restart with .jar file!.");
                if (jar.exists()) {     
                    WatchdogThread.doStop();
                for (Player ps : Bukkit.getOnlinePlayers()) {
                    ps.kickPlayer(configManager.messageReboot);
                }
                try
                {
                  Thread.sleep(100L);
                }
                catch (InterruptedException ex) {}
                MinecraftServer.getServer().getServerConnection().b();
                try
                {
                  Thread.sleep(100L);
                }
                catch (InterruptedException ex) {}
                try
                {
                  MinecraftServer.getServer().stop();
                }
                catch (Throwable t) {}
                Object shutdownHook = new Thread()
                {
                try {
                  Runtime.getRuntime().exec("Spigot.jar");
                }
            catch (Exception e)
            {
              e.printStackTrace();
            }
          }
        }
        ((Thread)shutdownHook).setDaemon(true);
        Runtime.getRuntime().addShutdownHook((Thread)shutdownHook);
              }

    But I test restart with spit.jar, so it lanch as process but server is not starting up
     
  2. Could you not just run the start-up batch file? Loop through all the files in the main directory, get its name and check if it ends with .bat, making sure that there's only one of them, and run it. Seems like less of a hassle than what you're doing.
     
Thread Status:
Not open for further replies.

Share This Page