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

[New API] Help with Configuration

Comments in 'Plugin Development' started by MasterBugPatch, Oct 20, 2014.

  1. MasterBugPatch
    Offline

    MasterBugPatch New Member

    Joined:
    Oct 20, 2014
    Posts:
    5
    Minecraft User:
    MasterBugPatch
    So in my plugin, my Config.yml basically looks like this:
    Code:
    MasterBugPatch:
      key: fa9ej
    redd1t:
      key: ka0e9
    What I'm asking is two questions:
    1) How can I check to see if Masterbugpatch or redd1t exist in an if statement?
    2) How would I be able to set a different key or get key from usernames?

    I do actually have most of question number two but I would really like to know the proper way to do this :).
    Thank you! :) I'm looking forward to any answers ;)

    One more thing to any developers who want to take the extra step to help me.
    Code:
    Masterbugpatch:
      key:
        - Key1
        - Key2
    How would I make a listed feature live above? How would I add on to the list, edit list, see what their list contains, etc.
    Last edited: Oct 20, 2014
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Basically, the whole config can be read into an array using $this->getConfig()->getAll(). Modify the array and eventually $this->getConfig()->setAll($array), and then $this->getConfig()->save(). Nevertheless, I don't advise you modify config.yml in code. If you want to save data, do it in another database.
    MasterBugPatch likes this.
  3. MasterBugPatch
    Offline

    MasterBugPatch New Member

    Joined:
    Oct 20, 2014
    Posts:
    5
    Minecraft User:
    MasterBugPatch
    Any way you can show me an example of how I would do that for my post above with the key?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am not sure what you want to do.
  5. MasterBugPatch
    Offline

    MasterBugPatch New Member

    Joined:
    Oct 20, 2014
    Posts:
    5
    Minecraft User:
    MasterBugPatch
    @PEMapModder For example if that was your Config.yml how would you edit just one of the players keys?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If it is mine, I don't want to edit it.

    Why can't you just tell us what exactly you want to do? Or do you really believe:
    (Source: a GitHub TODO issue that first mentioned the new API)
  7. MasterBugPatch
    Offline

    MasterBugPatch New Member

    Joined:
    Oct 20, 2014
    Posts:
    5
    Minecraft User:
    MasterBugPatch
    @PEMapModder I would like anyone to show me how to change MasterBugPatch/Reddit's key and get the key from code.
  8. MasterBugPatch
    Offline

    MasterBugPatch New Member

    Joined:
    Oct 20, 2014
    Posts:
    5
    Minecraft User:
    MasterBugPatch
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have an array $array = $this->getConfig()->getAll(). Just edit it like a normal array! If you don't know what is inside, var_export() it.
  10. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    He wants to know how to get one particular key (e.g. Redd1t) and set its key (e.g. "key: ka0e9").
    You could do this with the way @PEMapModder described above, with arrays. First of all, i suggest you look at Config's code here. Now, to check if a key exists, use the exists function. To set a value, theres a set function :p.
    I would assume, that, to set nested keys, you'd use setPath but i couls be wrong, as I havent really used Configs with Pocketmine before.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Since he is working with dynamic top-level keys, I think it would be better he manage the whole array as one thing, as working with the array would frequently require iterating through the whole array.

Share This Page

Advertisement