Set Forge custom Data to player


I have a probleme to set NBT to player i save they nbt when he player logout and i want to sync these nbt with all my server and i want to set these nbt to the player when he login on server
Isave player data with that

private static final DataQuery UnsafeData = DataQuery.of("UnsafeData","ForgeCaps");
DataContainer container = new;
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream zipOut = new GZIPOutputStream(out) {

DataFormats.NBT.writeTo(zipOut, container);


saving data is working is when i want to reset this data to player that don’t work i use this code

ByteArrayInputStream in = new ByteArrayInputStream(data);
GZIPInputStream zipIn = new GZIPInputStream(in);
DataContainer container = DataFormats.NBT.readFrom(zipIn);
Optional<DataView> unsafedata = container.getView(UnsafeData);

if someone have an idea tell me

That’s a bad advice, but if you limit your mod to forge (“ForgeCaps”), i’d just use NBTTagCompounds

how can i do this have you got some exemple pls

You have a player, cast it to EntityPlayerMC and call the seralization if you want to save the player to a nbt, and deserialization if you want to load the player from a nbt