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();
}
}
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));
}
}
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);
}
}
Aggregations