Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Aborting onEnable

Comments in 'Plugin Development' started by aliuly, May 18, 2015.

  1. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Hi,

    I have a plugin that does some runtime checks in the "onEnable" function. If these checks fail, I want to disable the plugin.

    What is the best way to do this?

    Right now I am using "trigger_error".
    Last edited: May 18, 2015
  2. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    You want exec code of onEnable after all plugins loaded
  3. ProjectInfinity
    Offline

    ProjectInfinity Active Member Plugin Developer

    Joined:
    Sep 7, 2014
    Posts:
    112
    Plugins:
    3
    Minecraft User:
    ProjectInfinity
    Disable it using the plugin manager?
  4. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I have rewritten my original post, hopefully it makes the question clearer.

    Obviously, that means that using "plugin manager" is not an option.
  5. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Code:
    public function onEnable(){
       #your code at start....
       
       $plugin = #your plugin name
       $this->getServer()->getPluginManager()->disablePlugin($plugin);
    
    }
    
    Does this help?
  6. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    That doesn't look right.

    What I have now (using trigger_error) shows up in the log as:

    Code:
    - Enabling plugin
    - Error message ....
    - Disabling plugin
    
    Your way seems a bit hackish...
    HotFireyDeath likes this.
  7. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Did you put in onDisable ?
  8. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    That does not do anything -_- in the current situation...
  9. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    I thought. But maybe both have to be there to run the plugin aswel as the PluginBase
  10. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    This thread doesn't have to do with running a plugin.
    It has to do with plugin executing a task on onEnable() and then quitting the plugin after onEnable() is finished.
  11. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    OK learning new stuff every day
    HotFireyDeath likes this.
  12. 64FF00
    Offline

    64FF00 Active Member Plugin Developer

    Joined:
    May 11, 2014
    Posts:
    298
    Plugins:
    2
    Minecraft User:
    64FF00
    Which of the following would be the best choice for disabling plugins? (Difficulty Level: UNKNOWN)

    ⓐ:
    PHP:
    [Plugin $plugin]->getPluginLoader()->disablePlugin($plugin);
    ⓑ:
    PHP:
    [Plugin $plugin]->setEnabled(false);
    ⓒ:
    PHP:
    [Plugin $plugin]->onDisable();
    ⓓ:
    PHP:
    [Server $server]->shutdown();
    Last edited: May 18, 2015
  13. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Maybe with foreach (onEnable()){ getPluginLoader()->diablePlugin ?
  14. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    what!?
    PEMapModder and HotFireyDeath like this.
  15. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    So I actually meant that when the thing in onEnable (if) is triggered then it should be deactivated
  16. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    [iThink]: A
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    ⓓ burns the whole forest just because one tree has wormholes.
    ⓒ just calls your implementation of onDisable(). PocketMine is in pure PHP; it doesn't change how PHP works. It won't do anything related to actually disabling the plugin.
    ⓑ disables the plugin on the PluginBase's context, but it still doesn't change what PluginManager and the event handlers think.
    ⓐ is correct.

    Actually, I have the fifth method that looks the best:
    PHP:
    throw new \RuntimeException("Runtime checks failed");
    PluginManager will gracefully accept the exception and disable your plugin.

    But make sure your onDisable() method won't trigger other errors, like call to close() on an uninitialized database.
    64FF00 and aliuly like this.

Share This Page

Advertisement