diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java index 3f053c6..423e661 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java @@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.API.Objects; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.block.BlockFace; import javax.annotation.Nonnull; import java.util.Map; @@ -17,6 +18,7 @@ public class LiftBlock implements Comparable { //Only used for cabine blocks, because those need caching! @Getter private final Material mat; @Getter private final byte data; + @Getter private final BlockFace face; @Getter private final String[] signLines; //Only used for inputs! @@ -33,6 +35,7 @@ public class LiftBlock implements Comparable { this.z = z; this.mat = null; this.data = 0; + this.face = null; this.signLines = null; this.floor = floor; } @@ -43,6 +46,7 @@ public class LiftBlock implements Comparable { this.y = y; this.z = z; this.mat = mat; + this.face = null; this.data = 0; this.signLines = null; this.floor = null; @@ -54,17 +58,19 @@ public class LiftBlock implements Comparable { this.y = y; this.z = z; this.mat = mat; + this.face = null; this.data = data; this.signLines = null; this.floor = null; } - public LiftBlock(String world, int x, int y, int z, Material mat, String[] signLines) { + public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String[] signLines) { this.world = world; this.x = x; this.y = y; this.z = z; this.mat = mat; + this.face = face; this.data = 0; this.signLines = signLines; this.floor = null; @@ -76,6 +82,7 @@ public class LiftBlock implements Comparable { this.y = y; this.z = z; this.mat = mat; + this.face = null; this.data = data; this.signLines = signLines; this.floor = null; diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java index 9807eb6..78feeb4 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java @@ -2,6 +2,8 @@ package nl.SBDeveloper.V10Lift.API.Objects; import lombok.Getter; import lombok.Setter; +import org.bukkit.Rotation; +import org.bukkit.block.BlockFace; @Getter @Setter public class LiftSign { diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java index 4af88e9..ed64c33 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.API.Runnables; import nl.SBDeveloper.V10Lift.API.Objects.*; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.DirectionUtil; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XSound; @@ -11,6 +12,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; import org.bukkit.block.Sign; +import org.bukkit.block.data.Directional; import org.bukkit.entity.Entity; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -189,6 +191,9 @@ public class MoveLift implements Runnable { state.setRawData(lib.getData()); } state.update(true); + if (block.getBlockData() instanceof Directional) { + DirectionUtil.setDirection(block, lib.getFace()); + } lb = lift.getBlocks().first(); for (Entity ent : Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getChunk().getEntities()) { v10ent = new V10Entity(ent, null, 0); @@ -229,6 +234,9 @@ public class MoveLift implements Runnable { state.setRawData(lib.getData()); } state.update(true); + if (block.getBlockData() instanceof Directional) { + DirectionUtil.setDirection(block, lib.getFace()); + } lift.getBlocks().add(lib); if (lib.getSignLines() != null) { bs = block.getState(); @@ -314,6 +322,9 @@ public class MoveLift implements Runnable { state.setRawData(lib.getData()); } state.update(true); + if (block.getBlockData() instanceof Directional) { + DirectionUtil.setDirection(block, lib.getFace()); + } } veiter = lift.getToMove().iterator(); while (veiter.hasNext()) { @@ -334,6 +345,9 @@ public class MoveLift implements Runnable { state.setRawData(lib.getData()); } state.update(true); + if (block.getBlockData() instanceof Directional) { + DirectionUtil.setDirection(block, lib.getFace()); + } lift.getBlocks().add(lib); if (lib.getSignLines() != null) { bs = block.getState(); diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index a5cd983..94f9791 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Runnables.MoveLift; import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager; import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager; +import nl.SBDeveloper.V10Lift.Utils.DirectionUtil; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; @@ -157,7 +158,8 @@ public class V10LiftAPI { if (type.toString().contains("SIGN")) { //SIGN if (XMaterial.isNewVersion()) { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block)); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines()); } else { Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); @@ -205,7 +207,8 @@ public class V10LiftAPI { if (type.toString().contains("SIGN")) { //SIGN if (XMaterial.isNewVersion()) { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block)); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines()); } else { Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); @@ -254,7 +257,8 @@ public class V10LiftAPI { if (type.toString().contains("SIGN")) { //SIGN if (XMaterial.isNewVersion()) { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block)); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines()); } else { Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java new file mode 100644 index 0000000..4216ce3 --- /dev/null +++ b/src/main/java/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java @@ -0,0 +1,30 @@ +package nl.SBDeveloper.V10Lift.Utils; + +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class DirectionUtil { + + @Nullable + public static BlockFace getDirection(@Nonnull Block block) { + if (block.getBlockData() instanceof Directional && block.getType().toString().contains("WALL_SIGN")) { + Directional dir = (Directional) block.getBlockData(); + return dir.getFacing(); + } + return null; + } + + public static void setDirection(@Nonnull Block block, BlockFace blockFace) { + if (block.getBlockData() instanceof Directional && block.getType().toString().contains("WALL_SIGN")) { + BlockData bd = block.getBlockData(); + Directional dir = (Directional) bd; + dir.setFacing(blockFace); + block.setBlockData(bd); + } + } +}