Solved Which would be best Yaml vs Class.

Discussion in 'Spigot Plugin Development' started by MajkTwyg, May 23, 2016.

  1. Hello, I'm currently developing a mini-games plugin for a server, and I'm questioning how I should be storing information.

    At the moment, I need to store locations, blocks, and integers; all data for Arenas that players can play in.

    What I had in mind was looping through all keys (arenas + key + node) during startup, pulling the information, and storing it in an 'Arena' class's variables for each arena instead of constantly seeking the config for information.

    So my question is which is better, storing in a class or pulling from a config file?
  2. Store in a yml file, cache in a class.
  3. @Redrield

    So essentially what I had in mind?
  4. Considering that storing in a class would be storing in RAM afaik, the data would be wiped when the program terminates.
    • Agree Agree x 2
  5. You'll only need config if you want to save information after restarting & reloads, or whenever the match is reset.
    • Agree Agree x 1
  6. Store in config what you need to persist between reloads/restarts. When you load a config file it loads the entire contents into memory anyway AFAIK.
  7. That's not really a problem considering I'll be reloading that data into memory when the server starts from the config.

    That's what I had in mind, I was just wondering if the difference between pulling from a config or the bloat of using class variables would make any difference.
  8. You just need to save data from the yml file into a class when the plugin enables, do operations to that data, not the data in the file, then write the cache into the yml when your plugin disables.
  9. I would think any difference would be quite negligible really. Do what makes the most sense IMO.
    • Informative Informative x 1
  10. Well in that case, I think I have my answer.

    Thanks everyone.
    • Friendly Friendly x 1
  11. I never really used YAML before, but JSON quite nice as well, especially while using Google' GSON library. Even though the library has some limitations, it's generally really nice, and extremely easy to work with.
    • Agree Agree x 1