run code only on reload

Discussion in 'Plugin Development' started by Trc202, Jul 28, 2011.

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

    Trc202

    I'd like to persist a blocklist only on reload of a server not the restart. The actual persistence is not the problem, figuring out if the server is shutting down or just reloading is. Any info in this matter is highly appreciated.
     
  2. Offline

    NuclearW

    Code:
    if(getServer().getOnlinePlayers().length != 0) {
    //There are players online, so it has to be a reload
    }
    This is usually what I do, but that only works for me because all the data I have to persist across a reload are player-related, so having a reload with no players on does not matter.

    Hope it helps.
     
  3. @Trc202 I'd recommend doing something like this:

    PHP:
    private boolean isReload false;

    public 
    void onDisable(){
        if(
    isReload){
             
    isReload false;
            
    //do stuff
        
    }
    }

    public 
    void onEnable(){
        
    isReload true;
    }
     
  4. Offline

    nisovin

    That seems... wrong. The onEnable method will have always run before onDisable, so isReload will always be true and that code will always run. Additionally, on a server reload I believe a new instance of the plugin is created, so that variable will go away anyway.
     
  5. Offline

    Trc202

    I ended up just saving everything and checking if the player is online the next time onEnable is called discarding the object if deemed un-necessary.
     
Thread Status:
Not open for further replies.

Share This Page