SPIGOT-5551: BlockState.setData fails when used by legacy plugin

This commit is contained in:
md_5 2020-01-29 09:22:43 +11:00
parent ab13a117a9
commit b1e96bd5ca
2 changed files with 16 additions and 8 deletions

View file

@ -90,7 +90,7 @@ public final class CraftLegacy {
return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData; 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"); Preconditions.checkArgument(material.isLegacy(), "fromLegacyData on modern Material");
MaterialData materialData = new MaterialData(material, data); MaterialData materialData = new MaterialData(material, data);
@ -107,11 +107,11 @@ public final class CraftLegacy {
return convertedBlock.getBlockData(); return convertedBlock.getBlockData();
} }
// Return existing block // Return air
return block.getBlockData(); 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?"); 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); MaterialData materialData = new MaterialData(material, (byte) data);
@ -137,8 +137,8 @@ public final class CraftLegacy {
} }
} }
// Return existing item // Return air
return item; return Items.AIR;
} }
public static byte toLegacyData(IBlockData blockData) { public static byte toLegacyData(IBlockData blockData) {

View file

@ -56,7 +56,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
} }
public static IBlockData getBlock(Material material, byte data) { 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) { public static MaterialData getMaterial(IBlockData data) {
@ -65,7 +65,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
public static Item getItem(Material material, short data) { public static Item getItem(Material material, short data) {
if (material.isLegacy()) { if (material.isLegacy()) {
return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), getItem(material), data); return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), data);
} }
return getItem(material); return getItem(material);
@ -114,10 +114,18 @@ public final class CraftMagicNumbers implements UnsafeValues {
} }
public static Item getItem(Material material) { public static Item getItem(Material material) {
if (material != null && material.isLegacy()) {
material = CraftLegacy.fromLegacy(material);
}
return MATERIAL_ITEM.get(material); return MATERIAL_ITEM.get(material);
} }
public static Block getBlock(Material material) { public static Block getBlock(Material material) {
if (material != null && material.isLegacy()) {
material = CraftLegacy.fromLegacy(material);
}
return MATERIAL_BLOCK.get(material); return MATERIAL_BLOCK.get(material);
} }