Solved PersistentDataContainer

Discussion in 'Spigot Plugin Development' started by Maxx_Qc, Jul 1, 2021.

  1. Hey guys, I’ve been looking into PersistentDataContainer recently and I have a question. You know how we all save our players data inside a file or database, would it be more effective or less effective to use the PersistentDataContainer? Is the database faster or the PersistantDataContainer? Are there more risks with data loss? I’m just trying to see what is the best performance wise and how it truly works.
    Thanks :)
     
  2. I think the PersistentDataContainer would be faster if and only if you don't need to synchronize data between servers as the data saved in the PersistentDataContainer is saved to the player data file of the player.
    Normally there should be no data loss with that only if the player data file is curropted
     
    • Informative Informative x 2
    • Agree Agree x 1
  3. This is correct.
    The reason people prefer using a database over PersistentDataContainer is mostly for consistency over servers and over resets.
    Meaning, if you're planning on resetting the server's data at some point, or you're afraid something might get corrupted and you want to make saves, or you want to look at the collective info then it's better to use a database, or want to change the world.
    If what you need is something to store temporary information, or there's no need to keep the information after a reset (or you're not planning a reset ever) then PersistentDataContainer is better purely because it's self contained within the server and much faster to access (and you don't have to worry about where to store - it's always in the world file).

    TL;DR:
    If you want something to store temporary info and don't mind loses (probably none, but you never know) and don't want (or care about) losing the data when changing the world (or resetting the server) then go with PersistentDataContainer.
    Otherwise use a database.

    IMO it's better to use a database most of the time unless it's for something like session info about the player.
     
    • Useful Useful x 1
  4. Is it not permanent tho? I’m confused, it’s like you’re saying it only exists for a session or did I read that wrong.
     
  5. It's permanent - it's stored in the world folder along with the rest of the server's data. So if you reset the server, the main world, or decide to restart the server from 0, then there is no (easy way) to move the info to the new save (stuff you might need like permissions, ranks, etc.).
    That's why I said that you should use it for stuff similar to session info - it's stays there as long as its not deleted manually.
     
    • Like Like x 1
  6. But if i move the players folder into the new world all the data’s are still gonna be there? Also, do you know if it takes a lot of space on the disk? Is it equivalent to a database, more or less?
     
  7. 1) You'll need to move the folder "playerdata" from within the world folder for that, but that would move everything about them - inventory, recipes unlocked, achievements, potion effects, etc. - it'll copy EVERYTHING about them (unless you want to develop a different program to run on each player's file and create a new one for them only with the PersistentDataContainer info).
    2) It depends on how you implement it I think. But frankly I have no clue. Either way I doubt it's more than a few bytes per player (a few kilobytes if you go mad with it).

    Overall, like I said before, unless it's something very temporary I suggest you use a database (even a local one that's file based) just for the possibility to move it in case of reset or changes to the world.
     
    • Like Like x 2