Wait, so.. If I use PlayerCreationEvent to create a custom player class, then I extend the close() function of Player.php to do my tasks before the player is kicked... would my tasks still be executed?
Very, very bad practise. Just don't. You should destroy all your instances onDisable. This will cause heavy problems with reloads. Just don't.
you can try foreach at onDisable() and for safety you can transfer him on PlayerKickEvent() by the PlayerKickEvent::getReason();
i think just use something like this hack 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} since there no better ways and PMMP dosent have a Server Initialized event or Server Shut Down Event
Or simply somebody wants to disable your plugin, through any means such as a plugin manager plugin. There are myriad reasons that your plugin can get disabled. Never assume the server is stopping just because your plugin is disabled, unless your plugin is only intended for your own use. Similary, never assume that the server has just started just because your plugin is enabled; for example, there may already be players online, especially after a reload. This is something that plugins handling sessions should note. A plugin should do absolutely nothing after it is disabled. Unless for very specific reasons, a disabling plugin in a stopping server or a disabling plugin that is just reloaded should do the theoretically same thing.
I believe that anything related to server stop should be done out of the server context. Otherwise it is only local to the plugin and should be done whenever plugin disables.