GateColumn(Location<World> topBlock, ConfigValue<List<SpongeBlockFilter>> allowedBlocks) { while (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), topBlock.getBlock())) { topBlock = topBlock.getRelative(Direction.UP); } topBlock = topBlock.getRelative(Direction.DOWN); this.topBlock = topBlock; }
@Override public boolean isValid(Location<World> location) { return BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), location.getBlock()) && (location.getBlockY() == 0 || !location.getRelative(Direction.DOWN).getBlockType().equals(BlockTypes.AIR)) && location.getRelative(Direction.UP).getBlockType().equals(BlockTypes.AIR); }
private void toggleColumns(BlockState state, Sign sign, @Nullable Humanoid human, Set<GateColumn> columns, Boolean forceState) { if (state == null) { state = BlockTypes.FENCE.getDefaultState(); } for (GateColumn vec : columns) { Location<World> col = vec.getBlock(); if (forceState == null) { forceState = !BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), col.getRelative(Direction.DOWN).getBlock()); } toggleColumn(col, sign, human, forceState, state); } }
@Listener public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) { if (event.getCause().containsType(PluginContainer.class)) { return; //Ignore plugin caused breaks. } if(ItemUtil.doesStackPassFilters(allowedItems.getValue(), player.getItemInHand(HandTypes.MAIN_HAND).orElse(null)) && !disabledPlayers.getValue().contains(player.getUniqueId())) { event.getTransactions().stream().filter((t) -> BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), t.getOriginal().getState())).forEach(transaction -> { Optional<TreeType> treeType = transaction.getOriginal().get(Keys.TREE_TYPE); treeType.ifPresent(treeType1 -> transaction.getOriginal().getLocation().ifPresent(location -> { List<Location> traversed = Lists.newArrayList(location); for(Direction dir : BlockUtil.getDirectFaces()) { checkBlocks(location.getRelative(dir), player, treeType1, traversed); } })); }); } }
private BlockState searchColumn(Location<World> block, Set<GateColumn> columns, BlockState state) { if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getBlock())) { GateColumn column = new GateColumn(block, allowedBlocks); Location<World> temp = column.topBlock; if(temp.getBlockType() != BlockTypes.AIR) { if(state == null) state = temp.getBlock(); if(state.equals(temp.getBlock())) columns.add(column); else return state; } while (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), temp.getBlock()) || temp.getBlockType() == BlockTypes.AIR) { if (!columns.contains(new GateColumn(temp.getRelative(Direction.NORTH), allowedBlocks))) state = searchColumn(temp.getRelative(Direction.NORTH), columns, state); if (!columns.contains(new GateColumn(temp.getRelative(Direction.SOUTH), allowedBlocks))) state = searchColumn(temp.getRelative(Direction.SOUTH), columns, state); if (!columns.contains(new GateColumn(temp.getRelative(Direction.EAST), allowedBlocks))) state = searchColumn(temp.getRelative(Direction.EAST), columns, state); if (!columns.contains(new GateColumn(temp.getRelative(Direction.WEST), allowedBlocks))) state = searchColumn(temp.getRelative(Direction.WEST), columns, state); temp = temp.getRelative(Direction.DOWN); } } return state; }
@Listener public void onEntityMove(MoveEntityEvent event) { Vector3d fromPosition = event.getFromTransform().getPosition(); Vector3d toPosition = event.getToTransform().getPosition(); if(Math.abs(toPosition.getY() - fromPosition.getY()) > sensitivity.getValue() && fromPosition.getY() - fromPosition.getFloorY() < 0.25) { Location<World> block = event.getFromTransform().getLocation().getRelative(Direction.DOWN); if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getBlock())) { Location<World> signBlock = block.getRelative(Direction.DOWN); if (SignUtil.isSign(signBlock)) { Sign sign = (Sign) signBlock.getTileEntity().get(); if (isMechanicSign(sign)) { doAction(event.getTargetEntity(), SignUtil.getTextRaw(sign, 2), event.getToTransform().getRotation()); } } } else { for (Map.Entry<SpongeBlockFilter, String> blockFilterStringEntry : autoBlocks.getValue().entrySet()) { if (blockFilterStringEntry.getKey().getApplicableBlocks().contains(block.getBlock())) { doAction(event.getTargetEntity(), blockFilterStringEntry.getValue(), event.getToTransform().getRotation()); } } } } }
if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), location.getBlock())) { if (((human instanceof Subject) && !usePermissions.hasPermission((Subject) human))) { if (human instanceof CommandSource)
while (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getBlock())) { for (ItemStack leftover : blockBag.add(Lists.newArrayList(blockBagItem.copy()))) { Item item = (Item) block.getExtent().createEntity(EntityTypes.ITEM, sign.getLocation().getPosition());
if(!BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), baseBlock.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(Text.builder("Can't use this material for a door!").build()); return true;
if(!BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), baseBlock.getBlock())) { if (block.getBlockType() != BlockTypes.WALL_SIGN) { bridgeDirection = Direction.UP; baseBlock = block.getRelative(bridgeDirection); if(!BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), baseBlock.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(notAllowedMaterial); return true;
@Listener public void onEntityMove(MoveEntityEvent event) { if(event.getTargetEntity().isOnGround()) { if(BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), event.getTargetEntity().getLocation().getRelative(Direction.DOWN).getBlock())) { FootprintData data = getFootprintData(event.getTargetEntity().getUniqueId()); if (data.canPlaceFootprint(event.getToTransform().getPosition())) { Vector3d footprintLocation = event.getToTransform().getPosition().add(0, 0.19, 0); //Flip these, it should 'roughly' rotate 90 or -90 degrees. Vector3d footOffset = new Vector3d(footprintLocation.getZ(), 0, footprintLocation.getX()).normalize().div(2); event.getTargetEntity().getWorld().spawnParticles(footprintParticle, footprintLocation.add(footOffset.mul(data.side ? -1 : 1))); data.position = event.getToTransform().getPosition(); data.side = !data.side; } } } }
private BlockState findColumns(Location<World> block, Set<GateColumn> columns, BlockState state) { int x = block.getBlockX(); int y = block.getBlockY(); int z = block.getBlockZ(); Location<World> closestColumn = null; Vector3d blockFlat = new Vector3d(block.getX(), 0, block.getZ()); for (int x1 = x - searchRadius.getValue(); x1 <= x + searchRadius.getValue(); x1++) { for (int y1 = y - searchRadius.getValue(); y1 <= y + searchRadius.getValue() * 2; y1++) { for (int z1 = z - searchRadius.getValue(); z1 <= z + searchRadius.getValue(); z1++) { if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getExtent().getBlock(x1, y1, z1))) { if(closestColumn == null) closestColumn = block.getExtent().getLocation(x1, y1, z1); else { Vector3d oldClosest = new Vector3d(closestColumn.getX(), 0, closestColumn.getZ()); Vector3d test = new Vector3d(x1, 0, z1); if(blockFlat.distanceSquared(test) < blockFlat.distanceSquared(oldClosest)) closestColumn = block.getExtent().getLocation(x1, y1, z1); } } } } } if(closestColumn != null) state = searchColumn(closestColumn, columns, state); return state; }