Fix door signs

This commit is contained in:
Daniel Saukel 2023-09-28 19:15:33 +02:00
parent 276fca5988
commit 05dfd8cb03
8 changed files with 70 additions and 12 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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())));
}
}

View File

@ -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));

View File

@ -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();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@ -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;
}
}