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

Printing notes in the config?

Comments in 'Plugin Development' started by dxm_hippie, May 13, 2015.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    How can i make "#notes like this" in the config? i cant seem to figure it out ):
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Example..
    ---
    #set this to true to enable
    enable: "false"
    ___
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Default YAML doesn't have a function to write notes programmatically. So you need to write them manually in the file.
    But if you need to do this programmatically, you can write a blank file using fwrite(), ...
    dxm_hippie likes this.
  5. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I tried to just add them to the config also tried in the main.php where I have it writing the config. I will try the fwrite()
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    If you want an example, you can try this:
    PHP:
    $yaml_file fopen($this->getDataFolder() . "myconfig.yml""w");
    $yaml "---\n#Example 1\nexample1: 'test'\n#Example 2\nexample2: 'test 2'\n...";
    fwrite($yaml_file$yaml);
    fclose($yaml_file);
    Then you can load it simply using a PocketMine Config instance ;)
    dxm_hippie likes this.
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Use file_put_contents instead, and use \r\n instead of just \n to support all modern operating systems. Also, don't forget to check if the file already exists before saving a new one.
    dxm_hippie and PEMapModder like this.
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Thanks peeps! :D this was totally the hard way to do it tho lol i figured out how to just type them in the config and have it stay, what would be the reason to need to make it programmatically?
    HotFireyDeath likes this.
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If anyone is up for making a Config class which handles comment parsing. It would be really useful for plugin developers.
    LDX and PEMapModder like this.

Share This Page

Advertisement