Java Code Examples for org.bukkit.block.BlockState#getWorld()

The following examples show how to use org.bukkit.block.BlockState#getWorld() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: GriefDefender   File: CommonBlockEventHandler.java    License: MIT License 5 votes vote down vote up
public void handleBlockBreak(Event event, Object source, BlockState blockState) {
    if (!GDFlags.BLOCK_BREAK) {
        return;
    }
    // Ignore air blocks
    if (blockState.getBlock().isEmpty()) {
        return;
    }

    // Special case
    if (source instanceof Block) {
        if (NMSUtil.getInstance().isBlockScaffolding(((Block) source))) {
            return;
        }
    }

    Player player = source instanceof Player ? (Player) source : null;
    final Location location = blockState.getLocation();
    if (location == null) {
        return;
    }

    final World world = blockState.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    GDClaim targetClaim = this.storage.getClaimAt(location);

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_BREAK, source, blockState, player, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        ((Cancellable) event).setCancelled(true);
    }
}
 
Example 2
Source Project: Modern-LWC   File: ProtectionFinder.java    License: MIT License 4 votes vote down vote up
/**
 * Try and load a protection for a given block. If succeded, cache it locally
 *
 * @param block
 * @param noAutoCache if a match is found, don't cache it to be the protection we use
 * @return
 */
protected Result tryLoadProtection(BlockState block, boolean noAutoCache) {
    if (matchedProtection != null) {
        return Result.E_FOUND;
    }

    LWC lwc = LWC.getInstance();
    ProtectionCache cache = lwc.getProtectionCache();

    // Check the cache
    if ((matchedProtection = cache.getProtection(block)) != null) {
        searched = true;
        if (matchedProtection.getProtectionFinder() == null) {
            fullMatchBlocks();
            matchedProtection.setProtectionFinder(this);
            cache.addProtection(matchedProtection);
        }
        return Result.E_FOUND;
    }

    // Manual intervention is required
    if (block.getType() == Material.REDSTONE_WIRE || block.getType() == Material.REDSTONE_WALL_TORCH ||
            block.getType() == Material.REDSTONE_TORCH) {
        return Result.E_ABORT;
    }

    // don't bother trying to load it if it is not protectable
    if (!lwc.isProtectable(block)) {
        return Result.E_NOT_FOUND;
    }

    // Null-check
    if (block.getWorld() == null) {
        return Result.E_NOT_FOUND;
    }

    Protection protection = lwc.getPhysicalDatabase().loadProtection(block.getWorld().getName(), block.getX(), block.getY(), block.getZ());

    if (protection != null) {
        if (protection.getProtectionFinder() == null) {
            protection.setProtectionFinder(this);
            fullMatchBlocks();
            cache.addProtection(matchedProtection);
        }

        // ensure it's the right block
        if (protection.getBlockId() > 0) {
            if (protection.isBlockInWorld()) {
                if (noAutoCache) {
                    return Result.E_FOUND;
                }

                this.matchedProtection = protection;
                searched = true;
            } else {
                // Removing orrupted protection
                protection.remove();
            }
        }
    }

    return this.matchedProtection != null ? Result.E_FOUND : Result.E_NOT_FOUND;
}
 
Example 3
public BlockEventQuery(Event event, BlockState block) {
    this(event, block.getWorld(), block.getX(), block.getY(), block.getZ(), block);
}
 
Example 4
public BlockQuery(BlockState block) {
    this(block.getWorld(), block.getX(), block.getY(), block.getZ(), block);
}