From e3acc16490330f82d51aa370108edcacf36c8ea5 Mon Sep 17 00:00:00 2001 From: Jeshua Date: Sun, 13 Aug 2023 15:00:36 -0600 Subject: [PATCH] Fixing IllegalArgumentException when trying to deserialize a block from an older world with incompatible blockData --- .../underilla/spigot/impl/BukkitChunkReader.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Underilla-Spigot/src/main/java/com/jkantrell/mc/underilla/spigot/impl/BukkitChunkReader.java b/Underilla-Spigot/src/main/java/com/jkantrell/mc/underilla/spigot/impl/BukkitChunkReader.java index 6aa9ac6..9a3fe82 100644 --- a/Underilla-Spigot/src/main/java/com/jkantrell/mc/underilla/spigot/impl/BukkitChunkReader.java +++ b/Underilla-Spigot/src/main/java/com/jkantrell/mc/underilla/spigot/impl/BukkitChunkReader.java @@ -9,6 +9,8 @@ import com.jkantrell.nbt.tag.StringTag; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + import java.util.Optional; public class BukkitChunkReader extends ChunkReader { @@ -19,7 +21,7 @@ public BukkitChunkReader(Chunk chunk) { } - //IMPLEMENTATIONS + //IMPLEMENTATION @Override public Optional blockFromTag(CompoundTag tag) { Material m = Optional.ofNullable(tag) @@ -34,8 +36,16 @@ public Optional blockFromTag(CompoundTag tag) { block = new BukkitBlock(m.createBlockData()); return Optional.of(block); } - String dataString = TagInterpreter.COMPOUND.interpretBlockDataString(properties); - block = new BukkitBlock(m.createBlockData(dataString)); + + //IllegalArgumentException might be thrown if block data is not compatible with current version of Minecraft + //In such case, return plain block with no data + try { + String dataString = TagInterpreter.COMPOUND.interpretBlockDataString(properties); + block = new BukkitBlock(m.createBlockData(dataString)); + } catch (IllegalArgumentException e) { + block = new BukkitBlock(m.createBlockData()); + } + return Optional.of(block); } @Override