Search in sources :

Example 1 with AbstractExtentMask

use of com.sk89q.worldedit.function.mask.AbstractExtentMask in project FastAsyncWorldEdit by IntellectualSites.

the class CachedMask method test.

public boolean test(@Nullable Extent extent, BlockVector3 vector) {
    if (!hasExtent || !(extent instanceof AbstractExtentMask)) {
        return test(vector);
    }
    int x = vector.getX();
    int y = vector.getY();
    int z = vector.getZ();
    AbstractExtentMask mask = (AbstractExtentMask) getMask();
    try {
        boolean check = cache_checked.add(x, y, z);
        if (!check) {
            return cache_results.contains(x, y, z);
        }
        boolean result = mask.test(extent, vector);
        if (result) {
            cache_results.add(x, y, z);
        }
        return result;
    } catch (UnsupportedOperationException ignored) {
        boolean result = mask.test(extent, vector);
        resetCache();
        cache_checked.add(x, y, z);
        if (result) {
            cache_results.add(x, y, z);
        }
        return result;
    }
}
Also used : AbstractExtentMask(com.sk89q.worldedit.function.mask.AbstractExtentMask)

Example 2 with AbstractExtentMask

use of com.sk89q.worldedit.function.mask.AbstractExtentMask 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 3 with AbstractExtentMask

use of com.sk89q.worldedit.function.mask.AbstractExtentMask in project FastAsyncWorldEdit by IntellectualSites.

the class MaskTraverser method setNewExtent.

private void setNewExtent(Mask mask, Extent newExtent) {
    if (mask == null) {
        return;
    }
    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) {
                    setNewExtent(next, newExtent);
                }
            } catch (NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Mask next = (Mask) field.get(mask);
            setNewExtent(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) {
                setNewExtent(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)

Aggregations

AbstractExtentMask (com.sk89q.worldedit.function.mask.AbstractExtentMask)3 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)2 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2