Best way to store and retrieve player information?

Discussion in 'Plugin Development' started by trixo, Jun 18, 2020.

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

    trixo

    Hi I want to create a plugin and I need to store information about every player. What's the best way to do that?

    What is the best way to store and retrieve information about a player ?

    Say my plugin keeps track the money a player has. How would I store that information in a file?

    Would I have a file for every player and when the player executes a command to add or remove money from their account I would open the file, read and and write the new value?
    Or
    Have a single file for every player and read of that?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @trixo How much data do you want to store?
     
  3. Offline

    trixo

    About 1 kilobyte for every player
     
  4. Offline

    timtower Administrator Administrator Moderator

    Already considered a database?
     
  5. Offline

    trixo

    A database is an option but isn't it slower than using a file?
     
  6. Offline

    timtower Administrator Administrator Moderator

    File is also slower than caching the information.
    List the information that you want to store, because money should be handled by the economy plugin, not by you.
    Your 1 kilobyte seems a lot for a plugin.
     
  7. Offline

    DutchJellyV2

    You could try to use the YamlConfiguration. It's very easy to use and there are many tutorials for it. But like timtower said, it might not be a good idea to store 1kb for each player in there (that's around 1000 characters), which sounds more like a SQL or MongoDB job to me.

    Oh and maybe you already knew this, but to store something for a player you can simply map their unique id's to anything you want like your player balances. So something along the lines of
    Code:
    //playerfileconfig is of type 'YamlConfiguration'
    playerfileconfig.set(player.getUniqueId(), playerBalance);
    
    //playerfile is of type 'File'
    try{ playerfileconfig.save(playerfile); } catch(Exception e){}
    
    could work. I hope this helps you getting started!
     
    Last edited: Jun 18, 2020
Thread Status:
Not open for further replies.

Share This Page