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

Solved getNested() twice?

Comments in 'Plugin Development' started by Andrey Nazarchuk, Aug 20, 2015.

  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello everyone, how can I get a nested config twice?
    I wan to access coordinates of a numbered location in a world from the config, It looks like this:
    Code:
    $this->worlds = new Config($this->getDataFolder()."worlds.yml", Config::YAML, array(
      "JungleRuins" => "
       - 0
        - 128 
        - 5
        - 128
       - 1
        - 128
        - 5
        - 128
       - 2
        - 128
        - 5
        - 128
       - 3
        - 128
        - 5
        - 128
       - 4
        - 128
        - 5
        - 128
       - 5
        - 128
        - 5
        - 128
       - 6
        - 128
        - 5
        - 128
      - 7
        - 128
        - 5
        - 128
      ",
    //more here
      ));
    
    Basically I just want to access JungleRuins and then get nested again of "0" to get coordinates.
    Thanks people.
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    By the way, the array should look like this:
    PHP:

    $this
    ->worlds = new Config($this->getDataFolder()."worlds.yml"Config::YAML, array(
      
    "JungleRuins" => array(
       
    => array(
        
    128,
        
    5,
        
    128
       
    ), // and so on...
     
    )
    //more here
      
    ));
    And to acces 0:
    PHP:
    $coordsArray $this->worlds->getNested("JungleRuins.0");
    $coordsArray will then be an array with the three coordinates so you can for example use them in a: new Vector3($coordsArray[0], $coordsArray[1], $coordsArray[2]);
    iksaku and Andrey Nazarchuk like this.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Thank you, but how would I change the config?
  4. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    You mean change thee coordinates?
    Have a look at setNested()
    PHP:
    $this->worlds->setNested("JungleRuins.0", [123]);
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    THANK YOU SO MUCH YOU ARE AWESOME. I remember when we talked more and where planning a project together lol.
    luca28pet likes this.

Share This Page

Advertisement