From 0632e375cfab9b7d1f5ee5b0d76e5d183edb7c3f Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 18 Oct 2020 07:01:15 +1100 Subject: [PATCH] SPIGOT-6194: Read correct nbt compound into chunk pdc Previously spigots chunk pdc loading logic would read the entire chunk nbt compound into the persistent data container of the chunk instead of just reading the "BukkitValues". Furthermore this commit also now correctly checks if the nbt compounds of entities, tile entities and chunks actually have a value for the "BukkitValues" key, as the previous 'getCompound' call would always return an instance, the null check was useless. This commit now uses 'get', which returns null if no key exists and then runs an instanceof check to both validate a non-null instance and an NBTTagCompound instance. By: Bjarne Koll --- paper-server/nms-patches/ChunkRegionLoader.patch | 6 +++--- paper-server/nms-patches/TileEntity.patch | 6 +++--- .../java/org/bukkit/craftbukkit/entity/CraftEntity.java | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/paper-server/nms-patches/ChunkRegionLoader.patch b/paper-server/nms-patches/ChunkRegionLoader.patch index 762b49397b..fe03a3945e 100644 --- a/paper-server/nms-patches/ChunkRegionLoader.patch +++ b/paper-server/nms-patches/ChunkRegionLoader.patch @@ -23,9 +23,9 @@ object = new Chunk(worldserver.getMinecraftWorld(), chunkcoordintpair, biomestorage, chunkconverter, (TickList) object1, (TickList) object2, j, achunksection, (chunk) -> { loadEntities(nbttagcompound1, chunk); + // CraftBukkit start - load chunk persistent data from nbt -+ NBTTagCompound persistentBase = nbttagcompound1.getCompound("BukkitValues"); -+ if (persistentBase != null) { -+ chunk.persistentDataContainer.putAll(nbttagcompound1); ++ NBTBase persistentBase = nbttagcompound1.get("BukkitValues"); ++ if (persistentBase instanceof NBTTagCompound) { ++ chunk.persistentDataContainer.putAll((NBTTagCompound) persistentBase); + } + // CraftBukkit end }); diff --git a/paper-server/nms-patches/TileEntity.patch b/paper-server/nms-patches/TileEntity.patch index e2fc6b9a65..5d018c7cbb 100644 --- a/paper-server/nms-patches/TileEntity.patch +++ b/paper-server/nms-patches/TileEntity.patch @@ -26,9 +26,9 @@ + // CraftBukkit start - read container + this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); + -+ NBTTagCompound persistentDataTag = nbttagcompound.getCompound("PublicBukkitValues"); -+ if (persistentDataTag != null) { -+ this.persistentDataContainer.putAll(persistentDataTag); ++ NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues"); ++ if (persistentDataTag instanceof NBTTagCompound) { ++ this.persistentDataContainer.putAll((NBTTagCompound) persistentDataTag); + } + // CraftBukkit end } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 1da70bfe8a..f8d1fb8719 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -142,6 +142,7 @@ import net.minecraft.server.EntityZombie; import net.minecraft.server.EntityZombieHusk; import net.minecraft.server.EntityZombieVillager; import net.minecraft.server.IChatBaseComponent; +import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import org.bukkit.EntityEffect; import org.bukkit.Location; @@ -970,9 +971,9 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } public void readBukkitValues(NBTTagCompound c) { - NBTTagCompound base = c.getCompound("BukkitValues"); - if (base != null) { - this.persistentDataContainer.putAll(base); + NBTBase base = c.get("BukkitValues"); + if (base instanceof NBTTagCompound) { + this.persistentDataContainer.putAll((NBTTagCompound) base); } }