From f6c87b67261f0a9b4bb2175bedfc9dbf4602ba08 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 10 Jun 2021 19:59:17 +0100 Subject: [PATCH] Add null check to creating default NBT data --- .../bukkit/adapter/mc1_15_2/BlockMaterial_1_15_2.java | 2 +- .../bukkit/adapter/mc1_16_1/BlockMaterial_1_16_1.java | 2 +- .../bukkit/adapter/mc1_16_2/BlockMaterial_1_16_2.java | 2 +- .../bukkit/adapter/mc1_16_5/BlockMaterial_1_16_5.java | 2 +- .../com/sk89q/worldedit/world/block/BlockTypesCache.java | 9 +++++++-- .../sk89q/worldedit/world/registry/BlockMaterial.java | 2 ++ 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BlockMaterial_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BlockMaterial_1_15_2.java index 1355a9a74..7db8f8a29 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BlockMaterial_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BlockMaterial_1_15_2.java @@ -39,7 +39,7 @@ public class BlockMaterial_1_15_2 implements BlockMaterial { this.isTranslucent = !(boolean) ReflectionUtil.getField(Block.class, block, "v"); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null); - tile = new LazyCompoundTag_1_15_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); + tile = tileEntity == null ? null : new LazyCompoundTag_1_15_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); } public Block getBlock() { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BlockMaterial_1_16_1.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BlockMaterial_1_16_1.java index 97e2fd1f9..4b7816089 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BlockMaterial_1_16_1.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BlockMaterial_1_16_1.java @@ -41,7 +41,7 @@ public class BlockMaterial_1_16_1 implements BlockMaterial { this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null); - tile = new LazyCompoundTag_1_16_1(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); + tile = tileEntity == null ? null : new LazyCompoundTag_1_16_1(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); } public Block getBlock() { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BlockMaterial_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BlockMaterial_1_16_2.java index e3584c2d3..00f8be486 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BlockMaterial_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BlockMaterial_1_16_2.java @@ -41,7 +41,7 @@ public class BlockMaterial_1_16_2 implements BlockMaterial { this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null); - tile = new LazyCompoundTag_1_16_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); + tile = tileEntity == null ? null : new LazyCompoundTag_1_16_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); } public Block getBlock() { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BlockMaterial_1_16_5.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BlockMaterial_1_16_5.java index 243593540..e70bc0086 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BlockMaterial_1_16_5.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BlockMaterial_1_16_5.java @@ -41,7 +41,7 @@ public class BlockMaterial_1_16_5 implements BlockMaterial { this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null); - tile = new LazyCompoundTag_1_16_5(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); + tile = tileEntity == null ? null : new LazyCompoundTag_1_16_5(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound()))); } public Block getBlock() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java index a1b2cf507..0464a082c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java @@ -2,6 +2,7 @@ package com.sk89q.worldedit.world.block; import com.boydti.fawe.util.MathMan; import com.google.common.primitives.Booleans; +import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; @@ -98,7 +99,9 @@ public class BlockTypesCache { int ordinal = this.stateOrdinals[propId]; if (ordinal != -1) { int stateId = internalId + (propId << BIT_OFFSET); - BlockState state = new BlockState(type, stateId, ordinal, blockMaterial.getDefaultTile()); + CompoundTag defaultNBT = blockMaterial.getDefaultTile(); + BlockState state = defaultNBT != null ? new BlockState(type, stateId, ordinal, blockMaterial.getDefaultTile()) : + new BlockState(type, stateId, ordinal); states.add(state); } } @@ -106,7 +109,9 @@ public class BlockTypesCache { this.defaultState = states.get(this.stateOrdinals[defaultPropId]); } else { - this.defaultState = new BlockState(type, internalId, states.size(), blockMaterial.getDefaultTile()); + CompoundTag defaultNBT = blockMaterial.getDefaultTile(); + this.defaultState = defaultNBT != null ? new BlockState(type, internalId, states.size(), blockMaterial.getDefaultTile()) : + new BlockState(type, internalId, states.size()); states.add(this.defaultState); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockMaterial.java index ac06f04f6..875d654c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockMaterial.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.jnbt.CompoundTag; +import org.jetbrains.annotations.Nullable; /** * Describes the material for a block. @@ -179,6 +180,7 @@ public interface BlockMaterial { * * @return default tile entity data */ + @Nullable CompoundTag getDefaultTile(); /**