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

Saving match settings to yml

Comments in 'Plugin Development' started by AppPhil, Oct 4, 2015.

  1. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Hey there,

    I am trying to save some matches I can manually create with some commands.
    I have these things I want to save:
    - $name
    - $mapName
    - $signPos
    - $teamCount

    And I want them to be saved in a .yml or something like that like this:
    Code:
    <NameOfTheMatch>:
      mapname: <NameOfTheMap>
      signPos: <Vector3 signPosition>
      teamCount: <TeamCount>
    <AnotherMatch>:
    ...
    
    And I also want to read the file out when loading the plugin.
    Is there anywhere a tutorial how to do this?
    Or can someone help me?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    that <NameOfTheMatch> i can't do it, But i can replace it with match and...
    PHP:
    $yml yaml_parse(file_get_contents($this->getDataFolder() . "FileName.yml"));
    //and use this to "get" the things from YML:
    foreach($yml["NameOfTheMatch"/*you have to replace that <NameOfTheMatch> with that*/] as $match):
    //for example to get mapname :
    $mapname $match["mapname"];//to get it.
    endforeach;
    and so on. BUT the format is
    Code:
    ---
    NameOfTheMatch:
      - mapname: Map Name Here
        SignPosX: x position of the sign
        SignPosY: y position of the sign
        SignPosZ: z position of the sign
        TeamCount: TeamCount
    ...
    
    Last edited: Oct 5, 2015
    TheKofola12 and AppPhil like this.
  3. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    But that's only the way how I can load but not how I can save, right?
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    yeah, to save, create a folder next to src called recourses and create the file in it (config.yml) and write in it the default config which everyone will have as default when using the plugin. i might not understand you perfectly.
    TheKofola12 and AppPhil like this.
  5. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    I just want to save and load my Match-Objetcs. Maybe you can understand that better. Sorry but English is not my mother language. And thanks for your help.
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You can save them in arrays.
    PHP:
    $maps[$name] = array($name$mapName$signPos$teamCount);
    AppPhil likes this.
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I'll do a tutorial soon.. Because it also took me ages to figure it out..

    //on startup (onenable)
    $this->saveResource("match.yml");
    $this->match=new Config($this->getDataFolder()."match.yml");
    //$this->match now contains the array
    //this will set settings
    $this->match->set(key,value);
    //to save config
    $this->match->save();
    //and the best is you reload the config
    /$this->match->reload();
    AppPhil likes this.
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Can't you see he's asking about storing match data and not creating data files? BTW using data files to store temporary data isn't the most convenient way to store temporary data, arrays/objects are.
    AppPhil likes this.
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    to do it like you do:
    #NoMoreComments
    AppPhil likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    *resources
    Taha_The_Hacker likes this.
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    oops, i always have spelling bugs..
    TheKofola12 likes this.

Share This Page

Advertisement