diff --git a/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/GlowingBlockSign.java b/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/GlowingBlockSign.java index 96c1a593..900cdb39 100644 --- a/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/GlowingBlockSign.java +++ b/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/GlowingBlockSign.java @@ -9,8 +9,8 @@ import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.sign.Rocker; import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.player.DPermission; -import de.erethon.bedrock.misc.BlockUtil; import de.erethon.bedrock.misc.EnumUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxxl.DungeonsXXL; import de.erethon.dungeonsxxl.world.block.GlowingBlock; @@ -104,7 +104,7 @@ public class GlowingBlockSign extends Rocker { } ((DGameWorld) getGameWorld()).addGameBlock( - glowingBlock = new GlowingBlock(DungeonsXXL.getInstance(), BlockUtil.getAttachedBlock(getSign().getBlock()), color, time)); + glowingBlock = new GlowingBlock(DungeonsXXL.getInstance(), BlockUtilCompat.getAttachedBlock(getSign().getBlock()), color, time)); active = true; } diff --git a/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/InteractWallSign.java b/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/InteractWallSign.java index 502ebdce..33369f4f 100644 --- a/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/InteractWallSign.java +++ b/addon/core/src/main/java/de/erethon/dungeonsxxl/sign/InteractWallSign.java @@ -10,8 +10,8 @@ import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.dungeonsxl.sign.passive.InteractSign; import de.erethon.dungeonsxl.trigger.InteractTrigger; -import de.erethon.bedrock.misc.BlockUtil; import de.erethon.bedrock.misc.NumberUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; @@ -54,7 +54,7 @@ public class InteractWallSign extends InteractSign { @Override public void initialize() { InteractTrigger trigger = InteractTrigger.getOrCreate(NumberUtil.parseInt(getSign().getLine(1)), - BlockUtil.getAttachedBlock(getSign().getBlock()), (DGameWorld) getGameWorld()); + BlockUtilCompat.getAttachedBlock(getSign().getBlock()), (DGameWorld) getGameWorld()); if (trigger != null) { trigger.addListener(this); addTrigger(trigger); diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java index f5b3da3d..1bfad064 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/BedSign.java @@ -22,8 +22,8 @@ import de.erethon.dungeonsxl.api.sign.Passive; import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DPermission; -import de.erethon.bedrock.misc.BlockUtil; import de.erethon.bedrock.misc.NumberUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.TeamBed; import org.bukkit.block.Block; @@ -73,7 +73,7 @@ public class BedSign extends Passive { @Override public void initialize() { this.team = NumberUtil.parseInt(getLine(1)); - Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); + Block block = BlockUtilCompat.getAttachedBlock(getSign().getBlock()); if (Category.BEDS.containsBlock(block)) { if (getGame().getGroups().size() > team) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java index ec96e88f..0683c6b0 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/passive/ProtectionSign.java @@ -20,7 +20,7 @@ import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.sign.Passive; import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.player.DPermission; -import de.erethon.bedrock.misc.BlockUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.ProtectedBlock; import org.bukkit.block.Sign; @@ -66,7 +66,7 @@ public class ProtectionSign extends Passive { @Override public void initialize() { - ((DGameWorld) getGameWorld()).addGameBlock(new ProtectedBlock(api, BlockUtil.getAttachedBlock(getSign().getBlock()))); + ((DGameWorld) getGameWorld()).addGameBlock(new ProtectedBlock(api, BlockUtilCompat.getAttachedBlock(getSign().getBlock()))); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java index 8f9d181f..5da40090 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/rocker/OpenDoorSign.java @@ -22,6 +22,7 @@ import de.erethon.dungeonsxl.api.sign.Rocker; import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.player.DPermission; import de.erethon.bedrock.misc.BlockUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.block.LockedDoor; import org.bukkit.block.Block; @@ -79,7 +80,7 @@ public class OpenDoorSign extends Rocker { @Override public void initialize() { - Block block = BlockUtil.getAttachedBlock(getSign().getBlock()); + Block block = BlockUtilCompat.getAttachedBlock(getSign().getBlock()); if (Category.DOORS.containsBlock(block) || Category.FENCE_GATES.containsBlock(block) || Category.TRAPDOORS.containsBlock(block)) { if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { door = new LockedDoor(api, block.getRelative(BlockFace.DOWN)); diff --git a/core/src/main/java/de/erethon/dungeonsxl/trigger/RedstoneTrigger.java b/core/src/main/java/de/erethon/dungeonsxl/trigger/RedstoneTrigger.java index ff7d2509..b928c9b7 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/trigger/RedstoneTrigger.java +++ b/core/src/main/java/de/erethon/dungeonsxl/trigger/RedstoneTrigger.java @@ -21,6 +21,7 @@ import de.erethon.dungeonsxl.api.sign.Deactivatable; import de.erethon.dungeonsxl.api.sign.DungeonSign; import de.erethon.dungeonsxl.event.trigger.TriggerActionEvent; import de.erethon.bedrock.misc.BlockUtil; +import de.erethon.dungeonsxl.util.BlockUtilCompat; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.Bukkit; import org.bukkit.block.Block; @@ -82,7 +83,7 @@ public class RedstoneTrigger extends Trigger { public static RedstoneTrigger getOrCreate(Sign sign, DGameWorld gameWorld) { Block rtBlock; if (Category.WALL_SIGNS.containsBlock(sign.getBlock())) { - rtBlock = BlockUtil.getAttachedBlock(sign.getBlock()); + rtBlock = BlockUtilCompat.getAttachedBlock(sign.getBlock()); } else { rtBlock = sign.getBlock(); } diff --git a/core/src/main/java/de/erethon/dungeonsxl/util/BlockUtilCompat.java b/core/src/main/java/de/erethon/dungeonsxl/util/BlockUtilCompat.java new file mode 100644 index 00000000..f3c4e8c1 --- /dev/null +++ b/core/src/main/java/de/erethon/dungeonsxl/util/BlockUtilCompat.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2012-2022 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.util; + +import de.erethon.bedrock.compatibility.Version; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Directional; +import org.bukkit.material.Attachable; +import org.bukkit.material.MaterialData; + +/** + * @author Daniel Saukel + */ +public class BlockUtilCompat { + + /** + * Returns the block the given block is attached to. + * + * @param block the block to check + * @return the attached block + */ + public static Block getAttachedBlock(Block block) { + if (Version.isAtLeast(Version.MC1_13)) { + if (block.getBlockData() instanceof Directional) { + Directional data = (Directional) block.getBlockData(); + if (data.getFaces().size() == 4) { + return block.getRelative(data.getFacing().getOppositeFace()); + } + } + return block.getRelative(BlockFace.DOWN); + + } else { + MaterialData meta = block.getState().getData(); + BlockFace blockFace = BlockFace.DOWN; + if (meta instanceof Attachable) { + blockFace = ((Attachable) meta).getAttachedFace(); + } + return block.getRelative(blockFace); + } + } +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 63edf5a5..67a42c43 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -40,7 +40,6 @@ import de.erethon.dungeonsxl.trigger.Trigger; import de.erethon.dungeonsxl.trigger.TriggerType; import de.erethon.dungeonsxl.trigger.TriggerTypeDefault; import de.erethon.bedrock.compatibility.Version; -import de.erethon.bedrock.misc.BlockUtil; import de.erethon.bedrock.misc.FileUtil; import de.erethon.dungeonsxl.world.block.GameBlock; import de.erethon.dungeonsxl.world.block.LockedDoor; @@ -65,6 +64,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import de.erethon.dungeonsxl.api.dungeon.BuildMode; +import de.erethon.dungeonsxl.util.BlockUtilCompat; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel @@ -504,7 +504,7 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { if (sign == null) { continue; } - if ((block.equals(sign.getSign().getBlock()) || block.equals(BlockUtil.getAttachedBlock(sign.getSign().getBlock()))) && sign.isProtected()) { + if ((block.equals(sign.getSign().getBlock()) || block.equals(BlockUtilCompat.getAttachedBlock(sign.getSign().getBlock()))) && sign.isProtected()) { return true; } }