Best method for stopping the server from a plugin

Discussion in 'Plugin Development' started by ddj, Mar 18, 2011.

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

    ddj

    Hi,

    I have a question on the best way I could stop my server from within my plugin.
    Searching these forums I found 2 methods to do so.

    The first is using a commandsender:
    Code:
    CraftServer cs = (CraftServer) this.getServer();
    CommandSender coms = new ConsoleCommandSender(this.getServer());
    cs.dispatchCommand(coms,"stop");
    
    To me this looks like the best solution, but this only is working for me on build 556.
    It looks like it raises a permission problem on builds 526,531 and 541 because if I test help or list in stead of stop, this just works fine.

    Another way I found was the method @dv90 is using in the AutoStop plugin.
    In this plugin the server is stopped by just saving player/world data manually and terminate the JVM by invoking exit(0)
    This way I could save world and players, disable all plugins, and then just exit the jvm, but this leaves me with the feeling I probably missed something big:)

    So, what would be the way to go?
     
  2. Offline

    Kekec852

    ((CraftServer) this.getServer()).getServer().a();

    Will do save-all and stop
     
  3. Offline

    ddj

    I now understand why I couldnt find this method, it's from the MinecraftServer class:)

    Thanks for helping out!
     
Thread Status:
Not open for further replies.

Share This Page