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

Still having trouble saving, loading from yml

Comments in 'Plugin Development' started by minebuilder0110, Oct 25, 2015.

Thread Status:
Not open for further replies.
  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I have searched on the forum quite a lot but still can't find a way to save stuff to yml file, in this case, coordinate.yml. So my question is how to save, RETRIEVE DATA FROM IT, and deleting it.
    For example, the config have this data.
    data:
    playername:
    - 0
    - 12
    - 823

    So how would I write a code so that a new data is generated so that a player name is in there
    (kinda hard to explain, i mean how to create a new section like this:
    anotherplayer:
    - 123
    - 234
    - 345
    )
    and also how to write the code so that the value returns 823.
    Finally, upon server stop, does the playerquitevent get triggered?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $yml = new Config($this->getDataFolder().'coordinates.yml'Config::YAML);

    $key $player->getName(); // Steve
    $yml->setNested($key, array($x$y$z));
    $yml->getNested($key); // returns array of $x, $y and $z
    // Remove key
    $yml->remove($key);
    // End of session
    $yml->save();
    This will return:
    coordinates.yml
    Code:
    ---[]
    ...
    
    Yes an empty, because i removed that key after i set it.
    But what would the file look like if i didnt?
    coordinates.yml
    Code:
    ---
    Steve:
    - 83
    - 42
    - 94
    ...
    
    minebuilder0110 and PEMapModder like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For the code part: search the forums.
    For your grammar: you made two grammar mistakes in one sentence. It should be "For example, the config has these data."
    minebuilder0110 likes this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yes PlayerQuitEvent is triggered but there is no plugins that could Catch that event because plugins is disabled first.
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Thanks! I will try that out soon.
    I know, I'm not that great at grammar :/
    Is there a possible workaround for it?
Thread Status:
Not open for further replies.

Share This Page

Advertisement