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

Get config from another plugin

Discussion in 'Development' started by kaliiks, Jan 15, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    Can i get in plugin config of another plugin??
     
  2. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    I really don't even see the need to.... can't you just go to its folder then edit the config there?
     
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Try something like:
    PHP:
     Server::getInstance()->getPluginManager()->getPlugin($plugin)->getConfig(); 
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    something like new config ($plugin'sConfigLocation)
    but i suggest you to do it via API if possible
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Not every plugin uses $this->getConfig().
     
  6. kaliiks

    kaliiks Zombie

    Messages:
    250
    So, can i use
    PHP:
    Server::getInstance()->getPluginManager()->getPlugin("Core")->getDataFolder() . "config.yml"Config::YAML);
    ?
     
  7. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    It should be still possible to get the data out of the config.yml file like this
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    maybe... depends if that plugin uses config.yml or config.json or a base64 encoded config
     
    applqpak likes this.
  9. Magicode

    Magicode Baby Zombie

    Messages:
    183
    GitHub:
    magicode1
    I guess, as long as you know what you are looking for, it should work.
     
  10. Jesse2061

    Jesse2061 Silverfish

    Messages:
    19
    Oh..There are two ways to choose.
    One is that if you know or you can see the code of that plugin, open it and see which is the config variable. You can use getPlugin(PluginName)->"That variable" to get.
    Another is a stupid method...
    PHP:
    $this->cfg=new Config("plugins/Another Plugin's FolderName/"."config.yml",Config::YAML,array());
    Then you can manage it.
     
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    wtf? the path plugins/ is not valid in ANY system. (and even if, why do you expect plugins to be at the root?) What are you doing? Please note that you are specifying a real file path here. you should use the server object to get the server plugin path.
     
    applqpak likes this.
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    seeing as the plugin's config is names "config.yml", this should work:
    PHP:
    Server::getInstance()->getPluginManager()->getPlugin("Core")->getConfig();
     
    kaliiks likes this.
  13. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    $this->getServer () ->getDataPath (); It refers to the root files

    PHP:
    $cfg = new Config($this->getServer()->getDataPath()."/plugins/PluginName/config.yml"Config::YAML);
     
  14. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Bad method. You're assuming the plugin is loaded and has not failed to load it's default config.
     
  15. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    just a little tweak :D

    PHP:
    public $cfg;

        public function 
    checkConfig() {
            if(
    $this->getServer()->getPluginManager()->getPlugin("PluginName")->isEnabled()) {
                
    $this->cfg = new Config($this->getServer()->getDataPath()."plugins/PluginName/config.yml"Config::YAML);
            }
            else {
                
    $this->getLogger()->warning("plugin was not found.");
            }
        }
     
    kaliiks likes this.
  16. kaliiks

    kaliiks Zombie

    Messages:
    250
    thx
     
  17. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    If the plugin doesn't exist you cannot call isEnabled on it. And if you are already using the plugin manager why not just do:
    PHP:
        public function getDefaultConfigFrom(string $pluginName){
            if(
    $plugin $this->getServer()->getPluginManager()->getPlugin("PluginName") instanceof PluginBase) {
                return 
    $plugin->getConfig();
            }
            
    $this->getLogger()->warning("Plugin '".$pluginName."' was not found."); #Assuming this function is in your PluginBase
        
    }
        
        public function 
    getConfigFrom(string $pluginNamestring $configNamePath){
            if(
    $plugin $this->getServer()->getPluginManager()->getPlugin("PluginName") instanceof PluginBase){
                if(
    file_exists($plugin->getDataPath().$configNamePath)){
                     return new 
    Config($plugin->getDataPath().$configNamePathConfig::DETECT);
                }
            }
            
    $this->getLogger()->warning("Plugin '".$pluginName."' was not found."); #Assuming this function is in your PluginBase
        
    }
    [/QUOTE]
     
  18. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    also UNLESS you know the plugin well, dont assume they uses
    Plugins/PluginName/config.yml
    some developers like to use: /plugins/config/pluginName.yml
    But if you are very certain of the behavior you probably can get away with it
    even tho i am starting to get offtopic,
    mind telling us why?
    sometimes most decent plugins offer APIs to make getting it's config last resort
    (and i am assuming you own the other Core plugin so why not just add APIs there?)
     
    applqpak likes this.
  19. kaliiks

    kaliiks Zombie

    Messages:
    250
    I dont own others Core plugin
     
  20. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    ugh sigh,
    lets try this again
     
  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.