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
public function onDisable(). Gets fired when the plugin gets disabled, which is either because your plugin errors or the server restarts. (Or reloads?)
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.
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?
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
PHP: public function onDisable(){ if($this->getServer()->isRunning()) {$this->getLogger()->info("Test"); }} This don't work for me
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!
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.
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. }}