From 110c5cbfd556433c86022df1049a80d6deedd163 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Wed, 26 Feb 2020 20:32:34 +0100 Subject: [PATCH] Fixed casting issues for BlockBreakListener --- .../V10Lift/Listeners/BlockBreakListener.java | 7 +------ .../nl/SBDeveloper/V10Lift/Utils/DoorUtil.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java index da97b05..3f40e59 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java @@ -45,12 +45,7 @@ public class BlockBreakListener implements Listener { } for (LiftBlock lb : f.getRealDoorBlocks()) { - Location loc; - if (lb.getMat().toString().contains("DOOR")) { - loc = DoorUtil.getLowerLocationOfDoor(b); - } else { - loc = b.getLocation(); - } + Location loc = DoorUtil.getLowerLocationOfDoor(b); if (lb.getWorld().equals(Objects.requireNonNull(loc.getWorld(), "World is null at BlockBreakListener").getName()) && lb.getX() == loc.getBlockX() && lb.getY() == loc.getBlockY() diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java index 9136fbc..10ebaeb 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java @@ -86,6 +86,8 @@ public class DoorUtil { } public static Location getLowerLocationOfDoor(@Nonnull Block block) { + if (!isDoor(block)) return block.getLocation(); + if (XMaterial.isNewVersion()) { org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData(); Location lower; @@ -119,4 +121,15 @@ public class DoorUtil { } } + public static boolean isDoor(Block b) { + if (b == null) { + return false; + } + if (XMaterial.isNewVersion()) { + return b.getBlockData() instanceof org.bukkit.block.data.type.Door; + } else { + return b.getState().getData() instanceof org.bukkit.material.Door; + } + } + } \ No newline at end of file