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