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

More inside a config

Discussion in 'Development' started by abimalek, Jan 4, 2018.

  1. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    I'm learning to add stuff to configs so how would I get the data Under a username and get the Data under that would it be
    PHP:
    $player->get($player->getName())->get("Keys");
     
  2. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    PHP:
    $config = new Config($this->plugin->getDataFolder() . $player->iusername ".yml"Config::YAML, array("thing" => "hello"));
    $config->get("thing"); //returns hello
    Modifying will be like
    PHP:
    $config->set("thing""bye");
    $config->save();
     
    LewBr likes this.
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Add an array into the config
    PHP:
    /** @var \pocketmine\utils\Config */
    $config->set("mainKey", ['usernames' => ['bill''bob']]);
    $config->save();

    $bill $config->get('mainKey')['usernames'][0];

    $bob $config->get('mainKey')['usernames'][1];
     
    Sandertv likes this.
  4. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    How do I make more the 1 config
     
  5. Flavius12

    Flavius12 Spider Jockey

    Messages:
    32
    GitHub:
    flavius12
    What do you mean? Do you want to create more configuration files?
     
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Call the config class again with a different file name and save it to have more then one config file.
     
  7. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    For a different file you would need to create a new instance of the Config class and set the new files data to the data of the old file. ex)
    PHP:
    <?php
    $oldConfig 
    = new \pocketmine\utils\Config('pathToOldFile', \pocketmine\utils\Config::YAML);
    $newConfig = new \pocketmine\utils\Config('pathToNewFile', \pocketmine\utils\Config::YAML$oldConfig->getAll());
    $newConfig->save();
     
    HyGlobalHD likes this.
  8. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    I what to have a Players.yml file that acts like a config
     
  9. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    would this work
    PHP:
    <?php
     $this
    ->players = new Config($this->getDataFolder() . "Players.yml"Config::YAML);
     
  10. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    if I
    do that would I need to add a folder to resources with the name or would it automatically make it for me
     
  11. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    What are you using this for? I have no idea what you're trying to do.
     
  12. HyGlobalHD

    HyGlobalHD Spider Jockey

    Messages:
    25
    GitHub:
    HyGlobalHD
    Depends If You Want To Get From The Resource Folder Or From The Code It Self.

    Make The Config Manually From The Code
    PHP:
    //example
    $this->conf = new Config($this->getDataFolder() . "ConfigName.yml"CONFIG::YAML, array(
    "FromCode" => "ItWillMakeTheFileItself"
    ));
    Get The Config From resources folder
    PHP:
    //example 2
    $this->getResource("FromResourcesFolder.yml"); // get Resources
    $this->saveResource("FromResourcesFolder.yml"); // save the resource to the Folder

    $this->fromres = new Config($this->getDataFolder() . "FromResourcesFolder.yml");// let fromres to act as the conf 
    Note: This just example
     
    Last edited: Jan 9, 2018
  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.