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

Server stop (Event??)

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

  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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?
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    I'd say no if PocketMine checks if the Owner of the task (the plugin) is enabled
     
  3. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Very, very bad practise. Just don't. You should destroy all your instances onDisable. This will cause heavy problems with reloads. Just don't.
     
    HimbeersaftLP likes this.
  4. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    you can try foreach at onDisable() and for safety you can transfer him on PlayerKickEvent() by the PlayerKickEvent::getReason();
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    but onDisable can be triggered on reload OR disabled by some plugins
     
  6. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    then PlayerKickEvent::getReason(); xD
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Use onDisable()
    It's called before the players are kicked due to shutdown.
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    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
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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.
     
    HimbeersaftLP, Muqsit and Sandertv like this.
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    So basically there's no way to legitimately detect this, right?
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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.
     
    Muqsit likes this.
  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.