Search in sources :

Example 1 with ExtentFilterBlock

use of com.fastasyncworldedit.core.extent.filter.block.ExtentFilterBlock in project FastAsyncWorldEdit by IntellectualSites.

the class LimitExtent method apply.

@Override
public <T extends Filter> T apply(Iterable<BlockVector3> positions, T filter) {
    int size;
    if (positions instanceof Collection) {
        size = ((Collection<BlockVector3>) positions).size();
    } else if (positions instanceof Region) {
        BlockVector3 dim = ((Region) positions).getDimensions();
        size = dim.getX() * dim.getY() * dim.getZ();
    } else if (positions instanceof Extent) {
        BlockVector3 min = ((Extent) positions).getMinimumPoint();
        BlockVector3 max = ((Extent) positions).getMinimumPoint();
        BlockVector3 dim = max.subtract(min).add(BlockVector3.ONE);
        size = dim.getX() * dim.getY() * dim.getZ();
    } else {
        ExtentFilterBlock block = new ExtentFilterBlock(this);
        for (BlockVector3 pos : positions) {
            limit.THROW_MAX_CHECKS();
            try {
                filter.applyBlock(block.init(pos));
            } catch (FaweException e) {
                if (!limit.MAX_FAILS()) {
                    throw e;
                }
            }
        }
        return filter;
    }
    limit.THROW_MAX_CHECKS(size);
    limit.THROW_MAX_CHANGES(size);
    return super.apply(positions, filter);
}
Also used : AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) Extent(com.sk89q.worldedit.extent.Extent) ExtentFilterBlock(com.fastasyncworldedit.core.extent.filter.block.ExtentFilterBlock) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) Collection(java.util.Collection) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

ExtentFilterBlock (com.fastasyncworldedit.core.extent.filter.block.ExtentFilterBlock)1 FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)1 AbstractDelegateExtent (com.sk89q.worldedit.extent.AbstractDelegateExtent)1 Extent (com.sk89q.worldedit.extent.Extent)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Region (com.sk89q.worldedit.regions.Region)1 Collection (java.util.Collection)1