How to save player data?

Discussion in 'Spigot Plugin Development' started by msdaniel924, Jun 18, 2018.

  1. The way we all use, I think, is this

    Code (Text):
    //To save the name
    getConfig().set(player.getName()+".Name", player.getName() );

    //To save the UUID
    getConfig().set(player.getName()+".UUID", player.getUniqueUUID());
     
    And you keep doing the same with everything you want to save

    - iFedeFC
     
  2. Benz56

    Moderator Supporter

    Nobody does that and shouldn’t do that. Always use the UUID as the key; names can change.

    As for your storage options it depends on the scale of the data you’re saving. Flat file yml files are okay up to a certain point. Essentials is for example creating a folder with a file per user instead of a single file.

    SQLite and MySQL are great options for large amounts of data. Though if you’re saving as little data as you mentioned you should be fine using a flat file to begin with.

    Example:
    Code (YAML):
    PlayerData:
      UUIDofPlayer
    :
        name
    : Benz56
        kills
    : 10000
     
    • Winner Winner x 1