#Custom player data

1 messages · Page 1 of 1 (latest)

topaz sierra
#

Custom player data

astral hamlet
#

what player nbt are you saving?

topaz sierra
#

i am serializing entire player object to make it persistent across servers

#

pretty much everything that's saved to level.dat for the player

#
Minecraft Wiki

<player>.dat files are used by servers to store the state of individual players. The format is also used within level.dat files to store the state of the singleplayer player, which overrides any <player>.dat files with the same name as the singleplayer player. These files are in NBT format.

#

and i have some custom plugin specific data assigned to each user like next time the user can use an item or cooldowns

astral hamlet
#

a player object is saved into the .dat files right?

topaz sierra
#

it's and also it's serialized and saved to my mongodb so that other servers can access it

astral hamlet
#

ah i understand where you're talking about, you're trying to get the same state of the player on a different server

topaz sierra
#

yup

astral hamlet
#

hmm this is beyond my knowledge

topaz sierra
#

i have that working - i just don't know is it better to save my custom properties in wrapper class like

class User {
  private final Player player;
  private int points;
  private int nextSpecialItemUse;
}

or PersistentDataContainer on the Player itself.

astral hamlet
#

i wouldn't store the actual player object

#

since it can become invalid

#

whenever the player leaves the server

topaz sierra
#

obviously i save it and remove player object onQuit, the wrapper class is just for my plugin internals

#

then i just call ServerPlayer::restoreFrom(ServerPlayer oldPlayer, boolean alive) onJoin where oldPlayer is my database serialized player

#

and load custom data for my User.class

#

at this point it just seems as a better solution to use PersistentDataContainer if it works how I think it is

astral hamlet
#

you can store primitives and strings in it

topaz sierra
#

i can store byte[] - thus everything

astral hamlet
#

ah yes PersistentDataType.BYTE_ARRAY

#

but the pdc is used for small data

topaz sierra
#

i don't have anything big to store, skill cooldowns, points etc.

astral hamlet
#

i think it would be better to store it in some type of file/ db

topaz sierra
#

I do, i just don't know if it's better to store player and custom data separately or custom data inside PersistentDataStorage (which i assume just adds it to player's CompoundTag which i do save anyway)

astral hamlet
#

well i think its useless to store it in the pdc as its a new server and the pdc is different there for the player than the other server

topaz sierra
#

that's why i am overwriting it using NMS on the new server