简体   繁体   English

在 Eclipse 中停止 Minecraft 服务器

[英]Stopping Minecraft Server in Eclipse

I have been trying this for hours and I don't know what to do.我已经尝试了几个小时,但我不知道该怎么办。 I'm creating a Minecraft Bukkit plugin which it's supposed to have a "restart" command, which sends some warning messages and after that I would like to close the server.我正在创建一个 Minecraft Bukkit 插件,它应该有一个“重启”命令,它会发送一些警告消息,然后我想关闭服务器。 I created a batch file to do it but, I want Java to do it for me when the warnings are over, something like, idk:我创建了一个批处理文件来执行此操作,但是,当警告结束时,我希望 Java 为我执行此操作,例如 idk:

open("C:/Users/Blablabla/Desktop/close.bat"); open("C:/Users/Blablabla/Desktop/close.bat");

And for the moment I have this:目前我有这个:

public String document = "C:/Users/Joan-Server/Desktop/Server/closer.bat";

if (args[0].equalsIgnoreCase("restart")) {
    while(x != 0) {
        Bukkit.broadcastMessage(plugin.name + ChatColor.GOLD + "¡ATENCIÓN! " + ChatColor.WHITE + "Reinicio del servidor en "
            + ChatColor.RED + x + " segundos.");
        //Try--
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        x = x - 1;
    }
    //Try--
}

You could use something like this to execute your bat file:你可以使用这样的东西来执行你的 bat 文件:

try{    
    Process p = Runtime.getRuntime().exec("C:/path/to/file.bat");
    p.waitFor();

}catch( IOException ex ){
    //Catch if file doesn't exist or is inaccessible 
}
catch( InterruptedException ex ){
    //If the p.waitFor() is interrupted     
}

Use this to execute your restart script and you should be good to go!使用它来执行您的重启脚本,您应该一切顺利! Assuming your restart script stops the server, waits, and starts the server again.假设您的重启脚本停止服务器,等待,然后再次启动服务器。

Let me know if you need anything else!需要帮助请叫我!

You could also do your restart directly from your plugin via您也可以通过以下方式直接从您的插件重新启动

getServer().dispatchCommand(getServer().getConsoleSender(), "restart");

If you really want to run the batch file, use如果您真的想运行批处理文件,请使用

Runtime.getRuntime().exec("C:\\Users\\Blablabla\\Desktop\\close.bat");

If you also want to handle the console output of the bat file, check out this answer .如果您还想处理 bat 文件的控制台输出,请查看此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM