Read/Write Play Specific Data

Discussion in 'Plugin Development' started by pers2981, Apr 9, 2013.

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

    pers2981

    Hey there,

    I'm developing a simple plugin that stores/reads a fair bit of player specific data. For example, Class, Level, Skills etc. I more or less have the logic down pat, it's just the code which is causing some problems. I haven't worked in Java for quite some time so I'm a bit rusty in that regard.

    I plan to store the data in this manner.

    /Plugins/PluginName/Username/Money.yml - 500
    /Plugins/PluginName/Username/Class.yml - Mage
    Etc

    Currently I've hooked into the playerjoin/playerquit events. I plan on checking if the folder 'Plugins/PluginName/Username' exists, if it doesn't then the folder will be created. If it does exist, then I will read every file in the players data folder and add it to a 'PlayerData hashmap'. Of course, when the player leaves the server I would save their data to their /PluginName/Username/ files and then remove them from the hashmap.


    Would reading so many files cause an excess amount of lag? Should I simply use Playername.YML to store everything? If so, how would I parse the data?

    Should I use a hashmap to store player data? Or should I use a different method?

    Any/All code examples would be greatly appreciated, like I said. I have the logic down, I just don't know the code.

    How would I go about creating a hashmap, reading from .yml's. Creating .yml's etc.

    Thank you

    Warm Regards,
    Jacob
     
  2. Offline

    Codisimus

    so Money.yml will only contain one int and Class.yml will only contain one String?
     
  3. Offline

    pers2981

    Correct, that way I don't have to go through the hassle of parsing a large string of text. That being said, I'm not sure if it would be worth the performance drop. Loading all those files would no doubt effect the server performance.
     
  4. Offline

    Codisimus

    I think you are going about it the wrong way. You don't have to do any of the parsing if you are using YAML.
     
  5. Offline

    pers2981

    Yes, you're right. I've misunderstood how YAML works.
     
  6. Offline

    Codisimus

    pers2981 Before I used YAML I would've done a properties file

    Codisimus.properties:
    Code:
    money=500
    class=mage
    .
    .
    .
    or perhaps just a text file.

    you could set it up for parsing

    Users.txt
    Code:
    Codisimus;500;mage
    pers2981;1000;swordsman
    or read in by each line

    Codisimus.txt
    Code:
    500
    mage

    pers2981.txt
    Code:
    1000
    swordsman

    EDIT: with all of these you have to Integer.parseInt(); though.
     
  7. Offline

    pers2981

    I believe a properties file would be the best approach. Any links/resources in regards to reading/writing property files? Also any hash map resources?
     
  8. Offline

    Codisimus

    You now how to use a properties object? There is a store method as well as a load method. Everything is strings though.
     
  9. Offline

    pers2981

    I'll look into that, thanks. How would I put the data read into a hashmap?
     
Thread Status:
Not open for further replies.

Share This Page