Search in sources :

Example 1 with ResettableMask

use of com.fastasyncworldedit.core.function.mask.ResettableMask in project FastAsyncWorldEdit by IntellectualSites.

the class MaskTraverser method reset.

private void reset(Mask mask, Extent newExtent) {
    if (mask == null) {
        return;
    }
    if (mask instanceof ResettableMask) {
        ((ResettableMask) mask).reset();
    }
    Class<?> current = mask.getClass();
    while (current.getSuperclass() != null) {
        if (mask instanceof AbstractExtentMask) {
            AbstractExtentMask mask1 = (AbstractExtentMask) mask;
            mask1.setExtent(newExtent);
        } else {
            try {
                Field field = current.getDeclaredField("extent");
                field.setAccessible(true);
                field.set(mask, newExtent);
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        if (mask instanceof MaskIntersection) {
            MaskIntersection mask1 = (MaskIntersection) mask;
            try {
                Field field = mask1.getClass().getDeclaredField("masks");
                field.setAccessible(true);
                Collection<Mask> masks = (Collection<Mask>) field.get(mask);
                for (Mask next : masks) {
                    reset(next, newExtent);
                }
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Mask next = (Mask) field.get(mask);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        try {
            Field field = current.getDeclaredField("masks");
            field.setAccessible(true);
            Collection<Mask> masks = (Collection<Mask>) field.get(mask);
            for (Mask next : masks) {
                reset(next, newExtent);
            }
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask) Mask(com.sk89q.worldedit.function.mask.Mask) Collection(java.util.Collection) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask)

Example 2 with ResettableMask

use of com.fastasyncworldedit.core.function.mask.ResettableMask in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method setMask.

// FAWE end
// FAWE start - use MaskingExtent & ExtentTraverser
/**
 * Set a mask.
 *
 * @param mask mask or null
 */
public void setMask(Mask mask) {
    if (mask == null) {
        mask = Masks.alwaysTrue();
    } else {
        new MaskTraverser(mask).reset(this);
    }
    ExtentTraverser<MaskingExtent> maskingExtent = new ExtentTraverser<>(getExtent()).find(MaskingExtent.class);
    if (maskingExtent != null && maskingExtent.get() != null) {
        Mask oldMask = maskingExtent.get().getMask();
        if (oldMask instanceof ResettableMask) {
            ((ResettableMask) oldMask).reset();
        }
        maskingExtent.get().setMask(mask);
    } else if (mask != Masks.alwaysTrue()) {
        addProcessor(new MaskingExtent(getExtent(), mask));
    }
}
Also used : BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) WallMakeMask(com.fastasyncworldedit.core.function.mask.WallMakeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) Mask(com.sk89q.worldedit.function.mask.Mask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) MaskingExtent(com.sk89q.worldedit.extent.MaskingExtent)

Example 3 with ResettableMask

use of com.fastasyncworldedit.core.function.mask.ResettableMask in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method setSourceMask.

// FAWE end
// FAWE start - use source mast > mask
/**
 * Set a mask.
 *
 * @param mask mask or null
 */
public void setSourceMask(Mask mask) {
    if (mask == null) {
        mask = Masks.alwaysTrue();
    } else {
        new MaskTraverser(mask).reset(this);
    }
    ExtentTraverser<SourceMaskExtent> maskingExtent = new ExtentTraverser<>(getExtent()).find(SourceMaskExtent.class);
    if (maskingExtent != null && maskingExtent.get() != null) {
        Mask oldMask = maskingExtent.get().getMask();
        if (oldMask instanceof ResettableMask) {
            ((ResettableMask) oldMask).reset();
        }
        maskingExtent.get().setMask(mask);
    } else if (mask != Masks.alwaysTrue()) {
        SourceMaskExtent next = new SourceMaskExtent(getExtent(), mask);
        new ExtentTraverser(this).setNext(next);
    }
}
Also used : ExtentTraverser(com.fastasyncworldedit.core.util.ExtentTraverser) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) WallMakeMask(com.fastasyncworldedit.core.function.mask.WallMakeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) Mask(com.sk89q.worldedit.function.mask.Mask) SourceMaskExtent(com.fastasyncworldedit.core.extent.SourceMaskExtent) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask)

Aggregations

ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)3 Mask (com.sk89q.worldedit.function.mask.Mask)3 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)2 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)2 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)2 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)2 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)2 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)2 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)2 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)2 SourceMaskExtent (com.fastasyncworldedit.core.extent.SourceMaskExtent)1 ExtentTraverser (com.fastasyncworldedit.core.util.ExtentTraverser)1 MaskingExtent (com.sk89q.worldedit.extent.MaskingExtent)1 AbstractExtentMask (com.sk89q.worldedit.function.mask.AbstractExtentMask)1 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1