Fixed casting issues for BlockBreakListener

This commit is contained in:
stijnb1234 2020-02-26 20:32:34 +01:00
parent 0a69a63f3a
commit 110c5cbfd5
2 changed files with 14 additions and 6 deletions

View file

@ -45,12 +45,7 @@ public class BlockBreakListener implements Listener {
} }
for (LiftBlock lb : f.getRealDoorBlocks()) { for (LiftBlock lb : f.getRealDoorBlocks()) {
Location loc; Location loc = DoorUtil.getLowerLocationOfDoor(b);
if (lb.getMat().toString().contains("DOOR")) {
loc = DoorUtil.getLowerLocationOfDoor(b);
} else {
loc = b.getLocation();
}
if (lb.getWorld().equals(Objects.requireNonNull(loc.getWorld(), "World is null at BlockBreakListener").getName()) if (lb.getWorld().equals(Objects.requireNonNull(loc.getWorld(), "World is null at BlockBreakListener").getName())
&& lb.getX() == loc.getBlockX() && lb.getX() == loc.getBlockX()
&& lb.getY() == loc.getBlockY() && lb.getY() == loc.getBlockY()

View file

@ -86,6 +86,8 @@ public class DoorUtil {
} }
public static Location getLowerLocationOfDoor(@Nonnull Block block) { public static Location getLowerLocationOfDoor(@Nonnull Block block) {
if (!isDoor(block)) return block.getLocation();
if (XMaterial.isNewVersion()) { if (XMaterial.isNewVersion()) {
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData(); org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
Location lower; 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;
}
}
} }