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

Disable plugin and command in config.yml

Comments in 'Plugin Development' started by Jon, Oct 13, 2014.

  1. Jon
    Offline

    Jon Active Member Plugin Developer

    Joined:
    Sep 1, 2013
    Posts:
    201
    Plugins:
    3
    Minecraft User:
    Heromine14
    Is there any way that i can chose in the config.yml to enable or disable a command of the plugin or the entire plugin?
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yes. You can set the variable in config.yml. Example:
    Code:
    enabled: true 
    Then in onEnable() function of your plugin put:
    PHP:
    $this->cfg $this->getConfig()->getAll();
    if(
    $this->cfg["enabled"] != true){
        
    $this->getPluginLoader()->disablePlugin($this);
    }
    Darunia18, LDX and Jon like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This doesn't work. You should suicide by $this->getPluginManager()->disablePlugin($this)
  4. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    it crashed on me, i changed it to $this->getServer()->getPluginManager()->disablePlugin($this);
  5. Jon
    Offline

    Jon Active Member Plugin Developer

    Joined:
    Sep 1, 2013
    Posts:
    201
    Plugins:
    3
    Minecraft User:
    Heromine14
    It works on me the @EvolSoft's method
    Last edited: Oct 15, 2014
    EvolSoft likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oops. You understand anyways ;)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It won't. It won't deregister the handlers and blah. Also, return at the end of the if block.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In fact, doing $this->getConfig()->get("enabled") is as (or even more) efficient as (or than) storing the array to a field first.

Share This Page

Advertisement