diff --git a/common/src/main/java/taboolib/common/OpenResult.java b/common/src/main/java/taboolib/common/OpenResult.java index 4ab656622..bedf84506 100644 --- a/common/src/main/java/taboolib/common/OpenResult.java +++ b/common/src/main/java/taboolib/common/OpenResult.java @@ -2,7 +2,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.tabooproject.reflex.Reflex; + +import java.lang.reflect.Field; public class OpenResult { @@ -77,8 +78,30 @@ public static OpenResult failed() { * 从其他插件的 OpenResult 转换为当前插件的 OpenResult */ public static OpenResult cast(Object source) { - Object successful = Reflex.Companion.getLocalProperty(source, "successful"); - Object value = Reflex.Companion.getLocalProperty(source, "value"); + if (source == null) { + return failed(); + } + if (source instanceof OpenResult) { + return (OpenResult) source; + } + Object successful = readField(source, "successful"); + Object value = readField(source, "value"); return new OpenResult(Boolean.TRUE.equals(successful), value); } -} \ No newline at end of file + + private static Object readField(Object source, String fieldName) { + Class type = source.getClass(); + while (type != null) { + try { + Field field = type.getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(source); + } catch (NoSuchFieldException ignored) { + type = type.getSuperclass(); + } catch (IllegalAccessException ex) { + throw new IllegalStateException("Cannot access field '" + fieldName + "' in " + source.getClass().getName(), ex); + } + } + throw new IllegalArgumentException("Field '" + fieldName + "' not found in " + source.getClass().getName()); + } +}