From d8c35355fa7192d95e29ad11e6d14586704326b7 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 17 Apr 2017 00:24:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E9=BB=98=E8=AE=A4=E5=80=BC=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../YumCore/config/inject/AbstractInjectConfig.java | 10 +++++----- .../pw/yumc/YumCore/config/inject/InjectParse.java | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java b/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java index 9caa4ef..1100c23 100644 --- a/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java @@ -24,7 +24,7 @@ import pw.yumc.YumCore.config.exception.ConfigParseException; */ public abstract class AbstractInjectConfig { private static String INJECT_TYPE_ERROR = "配置节点 %s 数据类型不匹配 应该为: %s 但实际为: %s!"; - private static String INJECT_ERROR = "自动注入配置失败 可能造成插件运行错误 %s: %s!"; + private static String INJECT_ERROR = "配置节点 %s 自动注入失败 可能造成插件运行错误 %s: %s!"; private static String PATH_NOT_FOUND = "配置节点 %s 丢失 将使用默认值!"; protected ConfigurationSection config; @@ -69,12 +69,12 @@ public abstract class AbstractInjectConfig { private void hanldeValue(Field field, String path, Object value) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException, SecurityException, ConfigParseException { Class type = field.getType(); if (!type.equals(value.getClass())) { - value = InjectParse.parse(type, config, path); + value = InjectParse.parse(type, value, config, path); } if (type.equals(String.class)) { value = ChatColor.translateAlternateColorCodes('&', String.valueOf(value)); } - if (value != null && !type.isAssignableFrom(value.getClass())) { + if (!type.isAssignableFrom(value.getClass())) { Log.w("字段 %s 默认类型为 %s 但解析后为 %s 可能存在转换错误!", field.getName(), type.getName(), value.getClass().getName()); } field.set(this, value); @@ -182,10 +182,10 @@ public abstract class AbstractInjectConfig { Log.w(PATH_NOT_FOUND, path); applyDefault(field); } - if (value == null) { return; } } else { value = config.get(path); } + if (value == null) { return; } hanldeValue(field, path, value); } catch (IllegalArgumentException ex) { Log.w(INJECT_TYPE_ERROR, path, field.getType().getName(), value != null ? value.getClass().getName() : "空指针"); @@ -193,7 +193,7 @@ public abstract class AbstractInjectConfig { } catch (ConfigParseException e) { Log.w(e.getMessage()); } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException ex) { - Log.w(INJECT_ERROR, ex.getClass().getName(), ex.getMessage()); + Log.w(INJECT_ERROR, path, ex.getClass().getName(), ex.getMessage()); Log.d(ex); } } diff --git a/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java b/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java index b5653a7..f130a8f 100644 --- a/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java +++ b/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java @@ -33,9 +33,8 @@ public class InjectParse { new DateFormatParse(); } - public static Object parse(Class type, ConfigurationSection config, String path) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + public static Object parse(Class type, Object value, ConfigurationSection config, String path) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (allparse.containsKey(type)) { return allparse.get(type).parse(config, path); } - Object value = config.get(path); try { return type.getDeclaredMethod("valueOf", String.class).invoke(null, value); } catch (NoSuchMethodException | IllegalArgumentException ignored) {