Questions about storage

Discussion in 'Plugin Development' started by raGan., Jul 29, 2012.

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

    raGan.

    I need to store information about players in my plugin into yml file using YamlConfiguration or other type of storage and I would like to hear how more experienced people deal with this. I look for performance and flexibility. When I add something new in future versions, I want users to keep their old data if possible and I want to ease maintenance of the data overally.

    Which one is better ? - Currently I am using ObjectStream to store things as HashMap<String, String> or HashMap<String ArrayList<Integer>>. I don't need users to be able to modify those. Is it generally better to store things in yml file or does it depend only on one's preference ?

    When to save ? - Now I use intervals defined in config to save all information I need, 15 minutes by default. In my plugin, I listen for such events as BlockBreak or EntityDeath, so pretty much can be done in 15 minutes. Is is OK to save more often, even every minute to prevent data loss ? (I'm talking about few strings and integers, maybe one or two small string lists per player.)

    How to save ? - Is it better to save all information in one file or to create separate file for every player or every unit I need to keep information about ? What if I know exactly when I need those information (player join/leave) ? Is it wise to have more files and save current ones more frequently, if I know I need only few of them at a time ?

    Few tips ? - Share your knowledge with me please. I am new to java and plugin making so I need a lot of help, especially with storage.

    Thanks.
     
  2. Offline

    grandwazir

    I've recently started to serialize objects into .yml which works quite well. It is forwards compatible as well as long as you provide default values when deserializing. There is an example of this in the source of StarterKit; yaml seems to be the 'bukkit way'. If you are doing anything relational you might want to consider using the persistence framework in Bukkit although it can be a steep learning curve and has many long standing bugs with the Bukkit implementation.

    As for saving I would just save as you need to. You do not know if the server will crash and losing data is very annoying. I remember in one of the builds of Citizens when you reloaded you lost all changes because it forgot to save the data.

    If you are saving a large amount of data consistently you might want to consider using SQLite instead. Having lots of separate files may cause you issues when you are opening, reading and saving to multiple files at once. As a general rule if I have something which is not going to change regularly (world settings, chat prefixes, items for a starter kit) it goes in yaml. Otherwise it gets persisted.
     
  3. Offline

    raGan.

    I know, but in this case, I need to save really often. As I mentioned above, thigs may change every blockbreak.

    Thanks anyway, I think I'll just continue using object stream and keep my objects serializable.
     
Thread Status:
Not open for further replies.

Share This Page