Where is most logical to store player data?

Hello, I have a question regarding where to store player data: Is it more logical store player data in a custom made file or the player data file (using custom data)? What are the advantages and disadvantages to each?

Depends what it is.

If the data is associated to the players in-game identity/entity in the world it would be best to store it on the player. (e.g. mana level, extra inventory space)

If the data is some sort of preference that should be kept across restarts and world changes, you would be best off storing the data elsewhere, perhaps a h2 database, or a config file.

Storing the data on the player itself means that the data is copied when the world is copied. You don’t need to worry about worlds moving servers or getting loaded as different dimensions.

Storing it seperately, means the user needs to be aware of it and possibly migrate it with their plugins when they swap the worlds temporarily, e.g. don’t accidentally keep your inventory or economy when you are playing a custom adventure mode pack together.

Additionally, if the data is getting large, because you have had many players log in to the server, you would be best using a local database, remote database, or have 1 file per player. However that now means you need to deal with loading that data asynchronously every time you need it, else risk blocking the main thread.

Thanks! So it sounds like for storing data like economy data or job data would be best to store to the player?

1 Like

No, i would suggest you to use database everywhere.
Storing data to player object/world sounds nice but what if you will want to access those data from another server/webservice. If something wrong happens its easier to run one query on database instead of parsing nbt tags. If i would run a server and i had to choose between two economy plugins, where one will use database (postgres/mysql/orcale…) and second one will use nbt tags to save balances etc. i would always choose the first one.

I do a compromise.

I store my data in database files located alongside the world files INSIDE the world folders.

Seems to work okay.

I would always choose the second one. An external database is a bitch of a dependency that people throw in for no reason without thinking through the performance or doing things asynchronously.

Or ya know… people like me use databases just cuz.

An external database is the best and most efficient way how to store your data. However it requires some understanding from the developer.

No it really isn’t.

There is a large overhead to using external databases. You lose a lot of performance. The reason is I/O access. There’s a metric crapton of overhead for I/O.

What it is good for is storing large amounts of repetitive data that need constant access time.

What I find best is to keep everything in memory, and use databases as a form of serialization for persistence.

Basically, if you have a huge amount of data that you are only accessing a few times every so often, (Economy, balances, transactions, etc.) then databases are awesome.

If you have a small amount of data being accessed almost a hundred times a second, (Tsk tsk FoxGuard) then databases ARE NOT THE WAY TO GO.
If you’re like me and NEED databases for their ease of management per size, serializing from databases to memory and vice versa is best.

Best and most efficient way to store and run arbitrary queries on for relational data, sure. But if you don’t need arbitrary queries, if your data is mostly small enough to store in memory instead of on disk, if you need that data now and not whenever the query decides to return it’s completely the wrong choice.

If you are after something that guarantee’s atomicity, you require a sizeable amount of data (doesn’t fit in ram), and can deal with slower response times then yes a external database is the right choice.

Minecraft data is 99% of the time, the wrong thing to be storing in a relational database. Econ balances you could maybe make an exception on if you really badly wanted the atomicity, but even then the world save isn’t atomic, so you would be screwed anyway. The only reason for using one in a minecraft context, is if you are too lazy to use a proper solution for sharing data to external web processes.

We are not talking about caching right now, are we?

no, just direct access.

@Inscrutable has given the final say.

Write it down on a piece of paper and scan in the image to the server.