From 5815136865a2fa266bf2b20b6cc81daf37702ecb Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 3 Jul 2019 10:22:42 +1000 Subject: [PATCH] SPIGOT-5123: Snapshot tile entities can end up with a non-null world --- nms-patches/TileEntity.patch | 25 ++----------------- .../bukkit/craftbukkit/block/CraftBanner.java | 5 ++-- .../block/CraftBlockEntityState.java | 9 +++---- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/nms-patches/TileEntity.patch b/nms-patches/TileEntity.patch index b315b4ccae..ed6077af61 100644 --- a/nms-patches/TileEntity.patch +++ b/nms-patches/TileEntity.patch @@ -34,7 +34,7 @@ } public NBTTagCompound save(NBTTagCompound nbttagcompound) { -@@ -53,12 +70,24 @@ +@@ -53,6 +70,11 @@ nbttagcompound.setInt("x", this.position.getX()); nbttagcompound.setInt("y", this.position.getY()); nbttagcompound.setInt("z", this.position.getZ()); @@ -46,28 +46,7 @@ return nbttagcompound; } } - -+ // CraftBukkit start - @Nullable - public static TileEntity create(NBTTagCompound nbttagcompound) { -+ return create(nbttagcompound, null); -+ } -+ -+ @Nullable -+ public static TileEntity create(NBTTagCompound nbttagcompound, @Nullable World world) { -+ // CraftBukkit end - String s = nbttagcompound.getString("id"); - - return (TileEntity) IRegistry.BLOCK_ENTITY_TYPE.getOptional(new MinecraftKey(s)).map((tileentitytypes) -> { -@@ -70,6 +99,7 @@ - } - }).map((tileentity) -> { - try { -+ tileentity.setWorld(world); // CraftBukkit - tileentity.load(nbttagcompound); - return tileentity; - } catch (Throwable throwable) { -@@ -168,4 +198,13 @@ +@@ -168,4 +190,13 @@ }, this::getPosition}); } } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java index 1939a881e6..9269448f71 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java @@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.block; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; +import net.minecraft.server.BlockBannerAbstract; import net.minecraft.server.EnumColor; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagList; @@ -31,9 +32,7 @@ public class CraftBanner extends CraftBlockEntityState impleme public void load(TileEntityBanner banner) { super.load(banner); - if (banner.color != null) { - base = DyeColor.getByWoolData((byte) banner.color.getColorIndex()); - } + base = DyeColor.getByWoolData((byte) ((BlockBannerAbstract) this.data.getBlock()).b().getColorIndex()); // PAIL patterns = new ArrayList(); if (banner.patterns != null) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java index 57443ca6f0..2831419446 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java @@ -4,7 +4,6 @@ import com.google.common.base.Preconditions; import net.minecraft.server.BlockPosition; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.TileEntity; -import net.minecraft.server.World; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.TileState; @@ -28,7 +27,7 @@ public class CraftBlockEntityState extends CraftBlockState Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? " + block); // copy tile entity data: - this.snapshot = this.createSnapshot(tileEntity, world.getHandle()); + this.snapshot = this.createSnapshot(tileEntity); this.load(snapshot); } @@ -39,17 +38,17 @@ public class CraftBlockEntityState extends CraftBlockState this.tileEntity = tileEntity; // copy tile entity data: - this.snapshot = this.createSnapshot(tileEntity, null); + this.snapshot = this.createSnapshot(tileEntity); this.load(snapshot); } - private T createSnapshot(T tileEntity, World world) { + private T createSnapshot(T tileEntity) { if (tileEntity == null) { return null; } NBTTagCompound nbtTagCompound = tileEntity.save(new NBTTagCompound()); - T snapshot = (T) TileEntity.create(nbtTagCompound, world); + T snapshot = (T) TileEntity.create(nbtTagCompound); return snapshot; }