From b1e96bd5ca47e92f098156858bebe4d5bbe5f528 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 29 Jan 2020 09:22:43 +1100 Subject: [PATCH] SPIGOT-5551: BlockState.setData fails when used by legacy plugin --- .../org/bukkit/craftbukkit/legacy/CraftLegacy.java | 12 ++++++------ .../bukkit/craftbukkit/util/CraftMagicNumbers.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java b/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java index 4c56408858..1dfeda4871 100644 --- a/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java +++ b/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java @@ -90,7 +90,7 @@ public final class CraftLegacy { return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData; } - public static IBlockData fromLegacyData(Material material, Block block, byte data) { + public static IBlockData fromLegacyData(Material material, byte data) { Preconditions.checkArgument(material.isLegacy(), "fromLegacyData on modern Material"); MaterialData materialData = new MaterialData(material, data); @@ -107,11 +107,11 @@ public final class CraftLegacy { return convertedBlock.getBlockData(); } - // Return existing block - return block.getBlockData(); + // Return air + return Blocks.AIR.getBlockData(); } - public static Item fromLegacyData(Material material, Item item, short data) { + public static Item fromLegacyData(Material material, short data) { Preconditions.checkArgument(material.isLegacy(), "fromLegacyData on modern Material. Did you forget to define api-version: 1.13 in your plugin.yml?"); MaterialData materialData = new MaterialData(material, (byte) data); @@ -137,8 +137,8 @@ public final class CraftLegacy { } } - // Return existing item - return item; + // Return air + return Items.AIR; } public static byte toLegacyData(IBlockData blockData) { diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index afe4004ff2..68728b4d86 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -56,7 +56,7 @@ public final class CraftMagicNumbers implements UnsafeValues { } public static IBlockData getBlock(Material material, byte data) { - return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), getBlock(material), data); + return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), data); } public static MaterialData getMaterial(IBlockData data) { @@ -65,7 +65,7 @@ public final class CraftMagicNumbers implements UnsafeValues { public static Item getItem(Material material, short data) { if (material.isLegacy()) { - return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), getItem(material), data); + return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), data); } return getItem(material); @@ -114,10 +114,18 @@ public final class CraftMagicNumbers implements UnsafeValues { } public static Item getItem(Material material) { + if (material != null && material.isLegacy()) { + material = CraftLegacy.fromLegacy(material); + } + return MATERIAL_ITEM.get(material); } public static Block getBlock(Material material) { + if (material != null && material.isLegacy()) { + material = CraftLegacy.fromLegacy(material); + } + return MATERIAL_BLOCK.get(material); }