1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Detecting when the server is shutting down from a plugin

Discussion in 'Resources' started by dktapps, Jul 21, 2017.

  1. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    This is far easier than most people believe. No need for any events, simply

    Code:
    public function onDisable(){
        if(!$this->getServer()->isRunning()){
            //do things on server shutdown
        }else{
            //reload, plugin disabled or server crashed
        }
    }
    
    in your PluginBase.

    Do note however that this will not work in the event of a server crash, as the server is still judged to be "running" if it did not shut down correctly.
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    how do you get Player on onDisable()?
     
  3. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    Please explain what you mean, as I am unsure what you mean.
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    so, I want to transfer the player to a different server when my server shut down but I don't know how to get the Player
     
  5. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    That is a completely different topic to what dktapps has started.
    Please create that topic separately , as it helps for another user to search for the same issue as you.
     
    SOFe, iiFlamiinBlaze and Thunder33345 like this.
  6. gamegam

    gamegam Silverfish

    Messages:
    16
    GitHub:
    gamegam
    public function onDisable(){
    //ex(
    foreach($this->getServer()->getOnlinePlayers() as $p){
    if(!$this->getServer()->isRunning()){
    $p->sendMessage ("plugin error");
    }else{
    $p->sendMessage("good");
    }
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.