Search in sources :

Example 1 with Resettable

use of com.fastasyncworldedit.core.Resettable in project FastAsyncWorldEdit by IntellectualSites.

the class PatternTraverser method reset.

@SuppressWarnings({ "unchecked" })
private void reset(Object pattern, Extent newExtent) {
    if (pattern == null) {
        return;
    }
    if (pattern instanceof Resettable) {
        ((Resettable) pattern).reset();
    }
    Class<?> current = pattern.getClass();
    while (current.getSuperclass() != null) {
        if (newExtent != null) {
            try {
                Field field = current.getDeclaredField("extent");
                field.setAccessible(true);
                field.set(pattern, newExtent);
            } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("pattern");
            field.setAccessible(true);
            Object next = field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Object next = field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        try {
            Field field = current.getDeclaredField("material");
            field.setAccessible(true);
            Pattern next = (Pattern) field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        try {
            Field field = current.getDeclaredField("patterns");
            field.setAccessible(true);
            Collection<Pattern> patterns = (Collection<Pattern>) field.get(pattern);
            for (Pattern next : patterns) {
                reset(next, newExtent);
            }
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) Pattern(com.sk89q.worldedit.function.pattern.Pattern) Collection(java.util.Collection) Resettable(com.fastasyncworldedit.core.Resettable)

Aggregations

Resettable (com.fastasyncworldedit.core.Resettable)1 Pattern (com.sk89q.worldedit.function.pattern.Pattern)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1