Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
183 stars 48 forks source link

NBTUtil.write(NamedTag, File) does not save to .dat file properly #44

Closed i0xHeX closed 4 years ago

i0xHeX commented 4 years ago

I used this lib to change player location before it logins (AsyncPlayerPreLoginEvent), but looks like it does not save the file properly, even without changes. Simplified sample I tested:

// find file
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8));
File folderRoot = plugin.getDataFolder().getParentFile().getParentFile();
File folderWorld = new File(folderRoot, "world");
File folderPlayerData = new File(folderWorld, "playerdata");
File filePlayer = new File(folderPlayerData, uuid.toString() + ".dat");

// read & write
NamedTag tagFile = NBTUtil.read(filePlayer);
CompoundTag tagRoot = (CompoundTag) tagFile.getTag();
NBTUtil.write(tagFile, filePlayer);

And that's how file saved: c0e79713-eb16-3c1f-a9fa-726bd3382b9b.zip

Used version 5.3 from https://jitpack.io/.

P.S. I read location from file earlier, so no problems with file reading.

Querz commented 4 years ago

The NBTSerializer did not flush the data correctly. Use release 5.4 for the fix.