Avoid reflection in MaskTraverser if possible

This commit is contained in:
MattBDev 2020-03-02 22:53:50 -05:00
parent dd4d405b36
commit 57a4c993a1

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.util;
import com.boydti.fawe.object.mask.ResettableMask;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask;
import java.lang.reflect.Field;
import java.util.Collection;
@ -26,11 +27,16 @@ public class MaskTraverser {
}
Class<?> current = mask.getClass();
while (current.getSuperclass() != null) {
try {
Field field = current.getDeclaredField("extent");
field.setAccessible(true);
field.set(mask, newExtent);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
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) {
}
}
try {
Field field = current.getDeclaredField("mask");