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

Modifying Other Plugin's Configs

Comments in 'Plugin Development' started by Samueljh1, Mar 5, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Hi, is there a way i can modify another plugin's config w/ the PocketMine config tool? Because its lot better then plain old php file modification :p
  2. codmadnesspro
    Offline

    codmadnesspro Notable Member Plugin Developer

    Joined:
    Sep 11, 2013
    Posts:
    551
    Plugins:
    1
    Minecraft User:
    Codmadnesspro
    PocketMine config tool? You sure... never heard of it...
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    You know,
    PHP:

            $this
    ->saveDefaultConfig();
            
    $this->reloadConfig();

            
    $this->config->get();

    etc
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yes that you can. Create a new Config instance with the path of the config file you want to edit
    xFlare and Samueljh1 like this.
  5. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Example plz :pP
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    PHP:
    $yourconfig = new Config("path_of_other_plugin/config.yml"Config::YAML);
    Don't forget to include pocketmine/utils/Config
    Samueljh1 likes this.
  7. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    there it is :p i forgot it xD now i like everything you posted on this thread :D
    EvolSoft likes this.
  8. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    No, the path of the config will be different on every server. You must use the get data folder function!
    EvolSoft likes this.
  9. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    ik thats wat i did :p
  10. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    It was only an example :)
    xFlare likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $config = $this->getServer()->get plugin manager()->getPlugin("PluginName")->getConfig();

    $this->getConfig() not $this->config
    64FF00 and iJoshuaHD like this.
  12. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    At the end both methods work :)
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But if that plugin is loaded, only this method will make that plugin actually read the new config content rather than the old one.
    Also, this is faster as this doesn't require another file input and YAML parse.

    As for $this->config, it's a property private to PluginBase and not visible to your subclass.
  14. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    never thought of this one. thanks :)
    64FF00 likes this.
  15. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Yea, same - that's very useful :p
  16. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yes, you are right. Then if you are trying to read the default plugin configuration (config.yml) you don't have to specify the directory where the file is.
    But if you need to open a config file different from default plugin config you need to create a new Config instance
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Depends on that other plugin. You may want to use ReflectionClass for that. Because that other plugin may just not even reload the config, then it's useless.
    64FF00 and EvolSoft like this.
  18. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    How about modifying the main pocketmine.yml config file. Is that allowed?
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try not to do that. PocketMine has API functions.
    64FF00 likes this.
  20. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    The PocketMine API only seems to have a method to read pocketmine.yml. I can not find something to write to it.

    Ironically enough, getProperty reads Server::config (which is the pocketmine.yml object).

    ON the other hand, the functions named get|set Config String|Int|Bool|etc modify the Server:: properties attribute which points to the server.properties file.

Share This Page

Advertisement