Java Code Examples for org.spongepowered.api.block.BlockTypes#AIR

The following examples show how to use org.spongepowered.api.block.BlockTypes#AIR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EconomyUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
private Consumer<CommandSource> createSellCancelConfirmed(CommandSource src, Claim claim, Sign sign) {
    return confirm -> {
        if (!claim.getEconomyData().isForSale()) {
            return;
        }
        Location<World> location = null;
        if (sign != null) {
            location = sign.getLocation();
        } else {
            final Sign saleSign = SignUtil.getSign(((GDClaim) claim).getWorld(), claim.getEconomyData().getSaleSignPosition());
            if (saleSign != null) {
                location = saleSign.getLocation();
            }
        }
        if (location != null && location.getBlockType() != BlockTypes.AIR) {
            location.setBlockType(BlockTypes.AIR);
            SignUtil.resetSellData(claim);
            claim.getData().save();
            GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCELLED);
        }
    };
}
 
Example 2
Source File: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockInteract(final InteractBlockEvent event, @Root final Player player)
{
    //If AIR or NONE then return
    if (event.getTargetBlock() == BlockSnapshot.NONE || event.getTargetBlock().getState().getType() == BlockTypes.AIR)
        return;

    final Optional<Location<World>> optionalLocation = event.getTargetBlock().getLocation();
    if (!optionalLocation.isPresent())
        return;

    final Location<World> blockLocation = optionalLocation.get();

    final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canInteractWithBlock(blockLocation, player, true);
    if (!protectionResult.hasAccess())
    {
        event.setCancelled(true);
        return;
    }
    else
    {
        if(event instanceof InteractBlockEvent.Secondary && protectionResult.isEagleFeather())
            removeEagleFeather(player);
    }
}
 
Example 3
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void removeHanging() {
    int miny = this.miny;
    if (miny < 1) {
        miny = 1;
    }

    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = miny; y < snapshots[0].length - 1; y++) {
                BlockSnapshot block = snapshots[x][y][z];
                BlockSnapshot underBlock = snapshots[x][y - 1][z];

                if (underBlock.getState().getType() == BlockTypes.AIR || underBlock.getState().getType() == BlockTypes.WATER
                        || underBlock.getState().getType() == BlockTypes.LAVA || underBlock.getState().getType() == BlockTypes.LEAVES) {
                    if (this.notAllowedToHang.contains(block.getState().getType())) {
                        snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private int highestY(int x, int z, boolean ignoreLeaves) {
    int y;
    for (y = snapshots[0].length - 1; y > 0; y--) {
        BlockSnapshot block = this.snapshots[x][y][z];
        if (block.getState().getType() != BlockTypes.AIR &&
                !(ignoreLeaves && block.getState().getType() == BlockTypes.SNOW) &&
                !(ignoreLeaves && block.getState().getType() == BlockTypes.LEAVES) &&
                !(block.getState().getType() == BlockTypes.WATER) &&
                !(block.getState().getType() == BlockTypes.FLOWING_WATER) &&
                !(block.getState().getType() == BlockTypes.LAVA) &&
                !(block.getState().getType() == BlockTypes.FLOWING_LAVA)) {
            return y;
        }
    }

    return y;
}
 
Example 5
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    LocatableBlock locatable = e.getCause().first(LocatableBlock.class).orElse(null);
    if (locatable != null) {
        BlockState sourceState = locatable.getBlockState();

        //liquid check
        MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
        if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
            boolean allowdamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.flow_damage;

            Region r = RedProtect.get().rm.getTopRegion(locatable.getLocation(), this.getClass().getName());
            if (r == null && !allowdamage && locatable.getLocation().getBlockType() != BlockTypes.AIR) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 6
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
private GPClaim findNearbyClaim(Player player) {
    int maxDistance = GriefPreventionPlugin.instance.maxInspectionDistance;
    BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GPClaim claim = null;
    int count = 0;
    while (blockRay.hasNext()) {
        BlockRayHit<World> blockRayHit = blockRay.next();
        Location<World> location = blockRayHit.getLocation();
        claim = this.dataStore.getClaimAt(location);
        if (claim != null && !claim.isWilderness() && (playerData.visualBlocks == null || (claim.id != playerData.visualClaimId))) {
            playerData.lastValidInspectLocation = location;
            return claim;
        }

        BlockType blockType = location.getBlockType();
        if (blockType != BlockTypes.AIR && blockType != BlockTypes.TALLGRASS) {
            break;
        }
        count++;
    }

    if (count == maxDistance) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimTooFar.toText());
    } else if (claim != null && claim.isWilderness()){
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.blockNotClaimed.toText());
    }

    return claim;
}
 
Example 7
Source File: BlockUtils.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Optional<Location<World>> getTargetBlock(Player player, GPPlayerData playerData, int maxDistance, boolean ignoreAir) throws IllegalStateException {
    BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
    GPClaim claim = null;
    if (playerData.visualClaimId != null) {
        claim = (GPClaim) GriefPreventionPlugin.instance.dataStore.getClaim(player.getWorld().getProperties(), playerData.visualClaimId);
    }

    while (blockRay.hasNext()) {
        BlockRayHit<World> blockRayHit = blockRay.next();
        if (claim != null) {
            for (Vector3i corner : claim.getVisualizer().getVisualCorners()) {
                if (corner.equals(blockRayHit.getBlockPosition())) {
                    return Optional.of(blockRayHit.getLocation());
                }
            }
        }
        if (ignoreAir) {
            if (blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) {
                return Optional.of(blockRayHit.getLocation());
            }
        } else { 
            if (blockRayHit.getLocation().getBlockType() != BlockTypes.AIR &&
                    blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) {
                return Optional.of(blockRayHit.getLocation());
            }
        }
    }

    return Optional.empty();
}
 
Example 8
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 5 votes vote down vote up
private void removeSandstone() {
    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = snapshots[0].length - 2; y > miny; y--) {
                if (snapshots[x][y][z].getState().getType() != BlockTypes.SANDSTONE) {
                    continue;
                }

                BlockSnapshot leftBlock = this.snapshots[x + 1][y][z];
                BlockSnapshot rightBlock = this.snapshots[x - 1][y][z];
                BlockSnapshot upBlock = this.snapshots[x][y][z + 1];
                BlockSnapshot downBlock = this.snapshots[x][y][z - 1];
                BlockSnapshot underBlock = this.snapshots[x][y - 1][z];
                BlockSnapshot aboveBlock = this.snapshots[x][y + 1][z];

                // skip blocks which may cause a cave-in
                if (aboveBlock.getState().getType() == BlockTypes.SAND && underBlock.getState().getType() == BlockTypes.AIR) {
                    continue;
                }

                // count adjacent non-air/non-leaf blocks
                if (leftBlock.getState().getType() == BlockTypes.SAND ||
                        rightBlock.getState().getType() == BlockTypes.SAND ||
                        upBlock.getState().getType() == BlockTypes.SAND ||
                        downBlock.getState().getType() == BlockTypes.SAND ||
                        aboveBlock.getState().getType() == BlockTypes.SAND ||
                        underBlock.getState().getType() == BlockTypes.SAND) {
                    snapshots[x][y][z] = snapshots[x][y][z].withState(BlockTypes.SAND.getDefaultState());
                } else {
                    snapshots[x][y][z] = snapshots[x][y][z].withState(BlockTypes.AIR.getDefaultState());
                }
            }
        }
    }
}
 
Example 9
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 4 votes vote down vote up
private void reduceStone() {
    if (this.seaLevel < 1) {
        return;
    }

    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            int thisy = this.highestY(x, z, true);

            while (thisy > this.seaLevel - 1 && (this.snapshots[x][thisy][z].getState().getType() == BlockTypes.STONE
                    || this.snapshots[x][thisy][z].getState().getType() == BlockTypes.SANDSTONE)) {
                BlockSnapshot leftBlock = this.snapshots[x + 1][thisy][z];
                BlockSnapshot rightBlock = this.snapshots[x - 1][thisy][z];
                BlockSnapshot upBlock = this.snapshots[x][thisy][z + 1];
                BlockSnapshot downBlock = this.snapshots[x][thisy][z - 1];

                // count adjacent non-air/non-leaf blocks
                byte adjacentBlockCount = 0;
                if (leftBlock.getState().getType() != BlockTypes.AIR && leftBlock.getState().getType() != BlockTypes.LEAVES
                        && leftBlock.getState().getType() != BlockTypes.VINE) {
                    adjacentBlockCount++;
                }
                if (rightBlock.getState().getType() != BlockTypes.AIR && rightBlock.getState().getType() != BlockTypes.LEAVES
                        && rightBlock.getState().getType() != BlockTypes.VINE) {
                    adjacentBlockCount++;
                }
                if (downBlock.getState().getType() != BlockTypes.AIR && downBlock.getState().getType() != BlockTypes.LEAVES
                        && downBlock.getState().getType() != BlockTypes.VINE) {
                    adjacentBlockCount++;
                }
                if (upBlock.getState().getType() != BlockTypes.AIR && upBlock.getState().getType() != BlockTypes.LEAVES
                        && upBlock.getState().getType() != BlockTypes.VINE) {
                    adjacentBlockCount++;
                }

                if (adjacentBlockCount < 3) {
                    this.snapshots[x][thisy][z] = this.snapshots[x][thisy][z].withState(BlockTypes.AIR.getDefaultState());
                }

                thisy--;
            }
        }
    }
}