@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; }
@Override public boolean isMechanicSign(Sign sign) { return SignUtil.getTextRaw(sign, 1).equalsIgnoreCase("[Door Up]") || SignUtil.getTextRaw(sign, 1).equalsIgnoreCase("[Door Down]") || SignUtil.getTextRaw(sign, 1).equalsIgnoreCase("[Door]"); }