/** * @param sign treated as sign post if it is such, or else assumed to be a wall sign (i.e., if you * ask about a stone block, it's considered a wall sign). * @return the blank side of the sign opposite the text. In the case of a wall sign, the block in * this direction is the block to which the sign is attached. This is also the direction a * player would be facing when reading the sign; see {@link #getFront(Location)}. */ public static Direction getBack(Location sign) { Direction front = getFront(sign); if (front == null) return Direction.NONE; return front.getOpposite(); }
@Override public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) { if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) { Direction back = SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN; Location baseBlock = block.getRelative(back); Location otherSide = getOtherEnd(block, back, maximumLength); if (otherSide == null) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build()); return true; } Location otherBase = otherSide.getRelative(back.getOpposite()); if (!baseBlock.getBlock().equals(otherBase.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Both ends must be the same material!").build()); return true; } int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default. Location left = baseBlock.getRelative(SignUtil.getLeft(block)); Location right = baseBlock.getRelative(SignUtil.getRight(block)); // Calculate left distance Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); while (true) { if (leftBlocks >= maximumWidth) break; if (left.getBlock().equals(baseBlock.getBlock()) && otherLeft.getBlock().equals(baseBlock.getBlock())) { leftBlocks++; left = left.getRelative(SignUtil.getLeft(block)); otherLeft = otherLeft.getRelative(SignUtil.getLeft(block)); } else { break; } } // Calculate right distance Location otherRight = otherBase.getRelative(SignUtil.getRight(block)); while (true) { if (rightBlocks >= maximumWidth) break; if (right.getBlock().equals(baseBlock.getBlock()) && otherRight.getBlock().equals(baseBlock.getBlock())) { rightBlocks++; right = right.getRelative(SignUtil.getRight(block)); otherRight = otherRight.getRelative(SignUtil.getRight(block)); } else { break; } } baseBlock = baseBlock.getRelative(back); BlockState type = block.getRelative(back).getBlock(); if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState)) type = BlockTypes.AIR.getDefaultState(); while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) { baseBlock.setBlock(type); left = baseBlock.getRelative(SignUtil.getLeft(block)); for (int i = 0; i < leftBlocks; i++) { left.setBlock(type); left = left.getRelative(SignUtil.getLeft(block)); } right = baseBlock.getRelative(SignUtil.getRight(block)); for (int i = 0; i < rightBlocks; i++) { right.setBlock(type); right = right.getRelative(SignUtil.getRight(block)); } baseBlock = baseBlock.getRelative(back); } } else { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Door not activatable from here!").build()); return false; } return true; }