Server stop (Event??)

Discussion in 'Development' started by VentroxStudio, Jan 13, 2017.

  1. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Hey. Is there a way to check if the server is stopping? I tried to check it with PlayerKickEvent but that don't work on Server stop
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    799
    GitHub:
    Sandertv
    public function onDisable(). Gets fired when the plugin gets disabled, which is either because your plugin errors or the server restarts. (Or reloads?)
     
  3. HimbeersaftLP

    HimbeersaftLP Wither Skeleton

    Messages:
    1,471
    GitHub:
    HimbeersaftLP
    Yep reloads are counted too
     
  4. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    But how can I get $player in onDisable?
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    799
    GitHub:
    Sandertv
    Why would you want to get $player on disable?
     
    applqpak and HimbeersaftLP like this.
  6. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    I want to transfer the player to another server when the server stops
     
  7. HimbeersaftLP

    HimbeersaftLP Wither Skeleton

    Messages:
    1,471
    GitHub:
    HimbeersaftLP
    Use foreach with $this->getServer()->getOnlinePlayers()
     
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    799
    GitHub:
    Sandertv
    You can foreach the online players, but I'm not sure what the priority is of the server breakdown when disabling. If you're lucky plugins get disabled first, then the players get kicked, but if you're unlucky, and it is the other way around, you'll have to do it a different way.
     
    HimbeersaftLP likes this.
  9. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Ok thanks

    I will try it
     
  10. HimbeersaftLP

    HimbeersaftLP Wither Skeleton

    Messages:
    1,471
    GitHub:
    HimbeersaftLP
    Read Sandertv's post first
     
  11. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    That doesn't work. Is there an other way to do it before the plugin disables?
     
  12. Thunder33345

    Thunder33345 Moderator Staff Member Verified

    Messages:
    2,152
    GitHub:
    Thunder33345
    Yes you could, try this
    PHP:
    onDisable:
    if!(
    $this->getServer()->isrunning) {
    //do your stuff here
    //PMMP WILL wait for you to do your jobs, but some host will SIGKILL -9 if it takes too long
    }
    here is a example https://ghostbin.com/paste/5hq4a
    NOTE, it may or may not work everytime and so on, this is a HACK not some guarantee way
    also you will need to check the order but i think PMMP will kick players first?
     
    Last edited: Feb 15, 2017
    HimbeersaftLP and Sandertv like this.
  13. HimbeersaftLP

    HimbeersaftLP Wither Skeleton

    Messages:
    1,471
    GitHub:
    HimbeersaftLP
    Yep it does I think

    But one method would be to use commandpreprocess on the /stop command and then transfer all players and then stop the server
     
  14. Thunder33345

    Thunder33345 Moderator Staff Member Verified

    Messages:
    2,152
    GitHub:
    Thunder33345
    but what if some plugin called server->shutdown?
     
  15. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    PHP:
    public function onDisable(){
     if(
    $this->getServer()->isRunning()) {
    $this->getLogger()->info("Test");
      }
    }
    This don't work for me
     
  16. Thunder33345

    Thunder33345 Moderator Staff Member Verified

    Messages:
    2,152
    GitHub:
    Thunder33345
    Sorry i meant isRunning == false
     
  17. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    That worked. But I can't transfer the player. I tried to kick him. But that doesn't work.

    PHP:
    public function onDisable(){

    $players $this->getServer()->getOnlinePlayers();
    foreach(
    $players as $player) {
    $player->kick();
    }
    }
    *But transfer on kick works!
     
  18. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer Verified

    Messages:
    1,374
    GitHub:
    robske110
    You can quickly check that:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.php#L1900
    Plugins get disabled before the players get kicked, and that is there for a reason.
     
  19. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,483
    GitHub:
    muqsit
    I assume PlayerKickEvent is called during during shutdown.
    So you can use...
    PHP:
    public function onKick(PlayerKickEvent $event){
        if(
    $event->getReason() === $this->getServer()->getProperty("settings.shutdown-message""Server closed")){
            
    //code: $event->getPlayer() before being kicked for shutdown.
        
    }
    }
     
  20. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    736
    GitHub:
    SalmonDE
    Didn't robske just say:
     

Share This Page

  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.