I'm trying to save player NBT in an external file and be able to load it later when the player logs in.
In a PlayerLoggedInEvent listener I put the code:
NBTInputStream inputStream = new NBTInputStream(new GZIPInputStream(new FileInputStream(savedFile)));
CompoundTag savedCompound = (CompoundTag) inputStream.readTag();
for(Map.Entry<String, ITag> entry : savedCompound.getTags().entrySet()){
ITag tag = entry.getValue();
event.player.getEntityData().setTag(tag.getName(), getType(tag));
}
I implemented an NBT reader to parse through the data in the file, as you can't get the value or name of tags with the minecraft classes, so that's what ITag and CompoundTag are. getType(tag) just returns a new NBTBase of the correct type (NBTTagByte, NBTTagInt, etc) with the value in the ITag.
The NBT file is read just fine, however the player's NBT remains the same after this, as displayed by their inventory remaining empty rather than filling up with the saved inventory. How can I make it update with the new data?