private boolean toggleColumn(LocalPlayer player, ChangedSign sign, Block block, GateColumn column, boolean close, Set<GateColumn> visitedColumns, boolean smallSearchSize) {
// If we want to close the gate then we replace air/water blocks
// below with fence blocks; otherwise, we want to replace fence
// blocks below with air
ItemInfo item;
if (close)
item = new ItemInfo(column.getStartingPoint());
else
item = new ItemInfo(Material.AIR, 0);
CraftBookPlugin.logDebugMessage("Setting column at " + block.getX() + ":" + block.getY() + ":" + block.getZ() + " to " + item.toString(), "gates.search");
for (Vector bl : column.getRegion()) {
Block blo = BukkitUtil.toBlock(new BlockWorldVector(BukkitUtil.toWorldVector(block).getWorld(), bl));
//sign = BukkitUtil.toChangedSign(sign.getSign().getBlock());
if(sign == null) {
CraftBookPlugin.logDebugMessage("Invalid Sign!", "gates.search");
return false;
}
ChangedSign otherSign = null;
Block ot = SignUtil.getNextSign(BukkitUtil.toSign(sign).getBlock(), sign.getLine(1), 4);
if(ot != null)
otherSign = BukkitUtil.toChangedSign(ot);
if (sign.getLine(2).equalsIgnoreCase("NoReplace")) {
// If NoReplace is on line 3 of sign, do not replace blocks.
if (blo.getType() != Material.AIR && !isValidGateBlock(sign, smallSearchSize, new ItemInfo(blo), true))
break;
} else // Allowing water allows the use of gates as flood gates
if (!canPassThrough(sign, smallSearchSize, blo))
break;
// bag.setBlockID(w, x, y1, z, ID);
if (CraftBookPlugin.inst().getConfiguration().safeDestruction) {
if (!close || hasEnoughBlocks(sign, otherSign)) {
if (!close && isValidGateBlock(sign, smallSearchSize, new ItemInfo(blo), true))
addBlocks(sign, 1);
else if (close && canPassThrough(sign, smallSearchSize, blo) && isValidGateBlock(sign, smallSearchSize, item, true) && !item.isSame(blo))
removeBlocks(sign, 1);
blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);
} else if (close && !hasEnoughBlocks(sign, otherSign) && isValidGateBlock(sign, smallSearchSize, item, true))
if (player != null) {
player.printError("mech.not-enough-blocks");
return false;
}
} else
blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);
CraftBookPlugin.logDebugMessage("Set block " + bl.getX() + ":" + bl.getY() + ":" + bl.getZ() + " to " + item.toString(), "gates.search");
recurseColumn(player, sign, blo.getRelative(1, 0, 0), visitedColumns, close, smallSearchSize);
recurseColumn(player, sign, blo.getRelative(-1, 0, 0), visitedColumns, close, smallSearchSize);
recurseColumn(player, sign, blo.getRelative(0, 0, 1), visitedColumns, close, smallSearchSize);
recurseColumn(player, sign, blo.getRelative(0, 0, -1), visitedColumns, close, smallSearchSize);