Storing/Retrieving lots of data for an RPG plugin

Discussion in 'Plugin Development' started by TerraVale, Jun 30, 2013.

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

    TerraVale

    Hi. I've been brainstorming out ideas for an RPG plugin to program for my server, and have a question to ask regarding it all.

    Because it's an RPG plugin, I will -- of course -- need to store quite a lot of data under each player's name. To me, creating a map for every value I need to assign/store for the player seems highly inefficient. If I decide to use maps to store these key-value pairs, I'll have a minimum of 30-40 maps to deal with.

    Does anyone happen to know how I should be doing this?

    Thanks.
     
  2. TerraVale
    Essentials.
    Create a playername.yml for every player, store data there.
    Use maps though, and only transfer the data from the maps to the files onDisable.
     
  3. Offline

    Hoot215

    You could also do as Mineblemone suggested, but use a player wrapper instead of accessing the data from the file directly. Or you could use metadata. Or a database (although that might be overkill).
     
  4. Hoot215
    What I suggested is store data in hashmaps, onPlayerJoin load the players data, onDisable save the updated version.
     
  5. Offline

    TerraVale


    Oh, okay. Thanks for the suggestion, that will work nicely. It'll make it easy to modify individual player levels, if needed. I also noticed that you mentioned Essentials in your first post -- does Essentials provide an API to save/load data in the same way you've suggested?

    Thanks for the help!
     
  6. TerraVale
    Essentials uses the config for players method, which is why I said it.

    TerraVale
    And saving data should be pretty simple, but I think it's easier onPlayerLeave event - as it gives you the needed player name to find references to it in hashmaps.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  7. Offline

    TerraVale


    I currently disable the onPlayerLeave message and replace it with my own, but something weird has happened before which makes me a bit iffy with regards to using onPlayerLeave to save their data. Occasionally, if the player crashes or end of streams, the onPlayerLeave event will not fire, and the default leave message will display. Would you happen to know if there's other checks with regards to a player crashing?

    If not, I may have to set it up so that on interval it will save all of the data, and check to see if any players still have their data loaded but are not actually online, then deal with it that way.
     
  8. Offline

    slayr288

    Mineblemone
    That's risky, since if the server crashes or is killed, onDisable is not called.
     
  9. Offline

    cummo15

    slayr288 How would you recommend doing this?
     
  10. Offline

    slayr288

    cummo15
    If it's a small amount of data being saved, then save it as you change it. If it's a large amount of data, store it in memory and save it when onDisable is called AND with a repeating async task that saves the data every 5-15 minutes or so.
     
  11. TerraVale
    Use both - onPlayerLeave to save the data, but also keep a hashmap<Boolean, String>, and onDisable check if any values are true (Set them to true on player join, with the string as player name, and false on player leave), and then use the playername to save the information. If you stop the server quickly enough in a crash, onDisable IS called, but in crashes data is usually lost anyway.
     
Thread Status:
Not open for further replies.

Share This Page