Java Code Examples for org.spongepowered.api.world.Location#getBlockType()

The following examples show how to use org.spongepowered.api.world.Location#getBlockType() . 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: 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 3
Source File: GDPlayerData.java    From GriefDefender with MIT License 4 votes vote down vote up
private void revertVisualBlocks(Player player, GDClaim claim, UUID visualUniqueId) {
    final List<Transaction<BlockSnapshot>> visualTransactions = this.visualClaimBlocks.get(visualUniqueId);
    if (visualTransactions == null || visualTransactions.isEmpty()) {
        return;
    }

    // Gather create block visuals
    final List<Transaction<BlockSnapshot>> createBlockVisualTransactions = new ArrayList<>();
    for (Runnable runnable : this.createBlockVisualRevertRunnables.values()) {
        final ClaimVisualRevertTask revertTask = (ClaimVisualRevertTask) runnable;
        if (revertTask.getVisualUniqueId().equals(visualUniqueId)) {
            continue;
        }
        final List<Transaction<BlockSnapshot>> blockTransactions = this.createBlockVisualTransactions.get(revertTask.getVisualUniqueId());
        if (blockTransactions != null) {
            createBlockVisualTransactions.addAll(blockTransactions);
        }
    }

    for (int i = 0; i < visualTransactions.size(); i++) {
        BlockSnapshot snapshot = visualTransactions.get(i).getOriginal();
        // If original block does not exist, do not send to player
        final Location<World> location = snapshot.getLocation().orElse(null);
        if (location != null && (snapshot.getState().getType() != location.getBlockType())) {
            if (claim != null) {
                claim.markVisualDirty = true;
            }
            continue;
        }
        boolean ignoreVisual = false;
        for (Transaction<BlockSnapshot> createVisualTransaction : createBlockVisualTransactions) {
            if (createVisualTransaction.getOriginal().getLocation().equals(snapshot.getLocation().get())) {
                ignoreVisual = true;
                break;
            }
        }
        if (ignoreVisual) {
            continue;
        }
        player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
    }
    if (claim != null) {
        claim.playersWatching.remove(this.playerID);
    }

    this.claimVisualRevertTasks.remove(visualUniqueId);
    this.visualClaimBlocks.remove(visualUniqueId);
    this.createBlockVisualRevertRunnables.remove(visualUniqueId);
    this.createBlockVisualTransactions.remove(visualUniqueId);
}
 
Example 4
Source File: ProtectionManager.java    From FlexibleLogin with MIT License 4 votes vote down vote up
private boolean isSafe(Location<World> loc) {
    return loc.getBlockType() != BlockTypes.PORTAL;
}