'How do I deserialize the Minecraft player.dat?
I'm trying to make a plugin for Velocity to sync player data among different sub servers.
I want to deserialize the player.dat which is saved in the /world/playerdata/ directory, then upload ut to MySQL. When a player connect a different sub server, I'll read the data in MySQL and send the data to the targeted sub server to make the player data synchronous.
Solution 1:[1]
It's solved by myself.
We can use NBTCompressedStreamTools, which you need to know about NMS, like this
File playerDataFolder = new File(getDataFolder().getParentFile().getParentFile(), "world\\playerdata\\");
File playerDat = new File(playerDataFolder, player.getUniqueId().toString() + ".dat");
try {
FileInputStream inputStream = new FileInputStream(playerDat);
NBTTagCompound nbt = NBTCompressedStreamTools.a(inputStream);
}catch (Exception e) {
e.printStackTrace();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wishrem |
