From 9e91bcabf29a5ef9bbfef8d0660c46bc243eaf35 Mon Sep 17 00:00:00 2001 From: Bjarne Koll 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. --- nms-patches/ChunkRegionLoader.patch | 6 +++--- nms-patches/TileEntity.patch | 6 +++--- .../java/org/bukkit/craftbukkit/entity/CraftEntity.java | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nms-patches/ChunkRegionLoader.patch b/nms-patches/ChunkRegionLoader.patch index 762b49397..fe03a3945 100644 --- a/nms-patches/ChunkRegionLoader.patch +++ b/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/nms-patches/TileEntity.patch b/nms-patches/TileEntity.patch index e2fc6b9a6..5d018c7cb 100644 --- a/nms-patches/TileEntity.patch +++ b/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/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 1da70bfe8..f8d1fb871 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/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); } }