From 415715d952c25e416c583249b1b8f04ddfade3f3 Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 6 Apr 2020 06:27:25 -0400 Subject: [PATCH] revert back to using Material for compatibility with old saves. --- .../utils/structure/StructureUtil.java | 2 +- .../skyblock/utils/world/block/BlockData.java | 15 ++++++--------- .../skyblock/utils/world/block/BlockUtil.java | 18 +++++++++--------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java b/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java index 08ac1456..8813d0ac 100644 --- a/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java +++ b/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java @@ -177,7 +177,7 @@ public final class StructureUtil { BlockUtil.convertBlockDataToBlock(blockLocation.getBlock(), blockDataList); } catch (Exception e) { SkyBlock.getInstance().getLogger() - .warning("Unable to convert BlockData to Block for type {" + blockDataList.getCompatibleMaterial() + ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + "}"); + .warning("Unable to convert BlockData to Block for type {" + blockDataList.getMaterial() + ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + "}"); } }); } diff --git a/src/main/java/com/songoda/skyblock/utils/world/block/BlockData.java b/src/main/java/com/songoda/skyblock/utils/world/block/BlockData.java index d9fcdf7d..fdbfdb2e 100644 --- a/src/main/java/com/songoda/skyblock/utils/world/block/BlockData.java +++ b/src/main/java/com/songoda/skyblock/utils/world/block/BlockData.java @@ -17,7 +17,6 @@ import java.util.Map; @SuppressWarnings("deprecation") public class BlockData { - private CompatibleMaterial compatibleMaterial; private String material; private String biome; private String stateType = BlockStateType.NORMAL.toString(); @@ -55,8 +54,8 @@ public class BlockData { private boolean exactTeleport = true; - public BlockData(CompatibleMaterial material, int x, int y, int z, String biome) { - this.compatibleMaterial = material; + public BlockData(String material, int x, int y, int z, String biome) { + this.material = material; this.x = x; this.y = y; this.z = z; @@ -64,14 +63,12 @@ public class BlockData { this.biome = biome; } - public CompatibleMaterial getCompatibleMaterial() { - if (compatibleMaterial == null) - return CompatibleMaterial.getMaterial(material); - return compatibleMaterial; + public String getMaterial() { + return this.material; } - public void setMaterial(CompatibleMaterial material) { - this.compatibleMaterial = material; + public void setMaterial(Material material) { + this.material = material.name(); } public String getBiome() { diff --git a/src/main/java/com/songoda/skyblock/utils/world/block/BlockUtil.java b/src/main/java/com/songoda/skyblock/utils/world/block/BlockUtil.java index 9eab1af6..4513595f 100644 --- a/src/main/java/com/songoda/skyblock/utils/world/block/BlockUtil.java +++ b/src/main/java/com/songoda/skyblock/utils/world/block/BlockUtil.java @@ -22,7 +22,7 @@ import java.util.List; public final class BlockUtil extends BlockUtils { public static BlockData convertBlockToBlockData(Block block, int x, int y, int z) { - BlockData blockData = new BlockData(CompatibleMaterial.getMaterial(block), x, y, z, block.getBiome().toString()); + BlockData blockData = new BlockData(block.getType().name(), x, y, z, block.getBiome().toString()); int NMSVersion = NMSUtil.getVersionNumber(); blockData.setVersion(NMSVersion); @@ -246,10 +246,10 @@ public final class BlockUtil extends BlockUtils { public static void convertBlockDataToBlock(Block block, BlockData blockData) { int NMSVersion = NMSUtil.getVersionNumber(); - CompatibleMaterial material = blockData.getCompatibleMaterial(); + String material = blockData.getMaterial(); if (material == null) return; - setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), material, blockData.getData()); + setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), Material.valueOf(material), blockData.getData()); // TODO Create a class to support biome changes // block.setBiome(Biome.valueOf(blockData.getBiome().toUpperCase())); @@ -424,10 +424,10 @@ public final class BlockUtil extends BlockUtils { String[] flower = blockData.getFlower().split(":"); int materialData = Integer.parseInt(flower[1]); - material = CompatibleMaterial.getMaterial(flower[0].toUpperCase()); + material = flower[0].toUpperCase(); if (material != null) { - ItemStack is = new ItemStack(material.getMaterial(), 1, (byte) materialData); + ItemStack is = new ItemStack(Material.getMaterial(material), 1, (byte) materialData); World world = block.getWorld(); @@ -462,16 +462,16 @@ public final class BlockUtil extends BlockUtils { if (blockData.getVersion() > 12) { if (NMSVersion > 12) { - material = CompatibleMaterial.valueOf(flower[0].toUpperCase()); + material = flower[0].toUpperCase(); } } else { if (NMSVersion < 13) { - material = CompatibleMaterial.valueOf(flower[0].toUpperCase()); + material = flower[0].toUpperCase(); } } if (material != null) { - flowerPot.setContents(new MaterialData(material.getMaterial(), (byte) Integer.parseInt(flower[1]))); + flowerPot.setContents(new MaterialData(Material.getMaterial(material), (byte) Integer.parseInt(flower[1]))); } state.setData(flowerPot); @@ -479,7 +479,7 @@ public final class BlockUtil extends BlockUtils { } } - if (blockData.getCompatibleMaterial().equals("DOUBLE_PLANT")) { + if (material.equals("DOUBLE_PLANT")) { Block topBlock = block.getLocation().add(0.0D, 1.0D, 0.0D).getBlock(); Block bottomBlock = block.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();