ServerShutdown Event?

Discussion in 'Plugin Development' started by iKeirNez, Jul 18, 2012.

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

    iKeirNez

    I am looking for a way to run something when the server stops/shuts down. I have tried using onDisable but it fires if the server is reloaded or if another plugin/tool disables the plugin.

    Is there anyway to do this then?

    Keir
     
    hcwool likes this.
  2. Offline

    ferrybig

    try registering a shutdown hook at the runtime class
     
    jthort and hcwool like this.
  3. Offline

    iKeirNez

    How would I go about doing that?

    Okay I sort of got it working, but the strange thing is that sometimes it works, and sometimes it doesn't. Any ideas? Here is my code.

    onEnable:
    Code:
    try {
                Runtime.getRuntime().addShutdownHook(new Handler_serverstop());
            } catch (Exception e){
                e.printStackTrace();
            }
    Handler_serverstop:
    Code:
    package com.github.zathrus_writer.commandsex.handlers;
     
    public class Handler_serverstop extends Thread {
     
        public void run() {
            System.out.println("Success YAYAYAYAYAYA!");
        }
    }
    ferrybig

    I seem to have got it all working, the issue was that after a certain amount of time you can no longer print to the console, so it still kicks the players :D Thanks ferrybig

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    ferrybig

    when the server is stopping, the logging system wil also stop, and some other things to, you cant realy om manny things when the server sstops
     
  5. Offline

    iKeirNez

    Kick in server stopping has worked 100% so far, will do more testing
     
  6. Offline

    ferrybig

    I noticed that loggers are also shutted down during the call fot hose threads and awt is also shutted down
     
  7. Offline

    iKeirNez

    Yeah, so if you print to the console by hooking into the shutdown runtime it is unreliable, but with most other things it should be fine. E.g. kicking players which is what I am doing.
     
Thread Status:
Not open for further replies.

Share This Page