From 2cad6e713a5233f932b2e0fcf295ac7da335627e Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 8 Feb 2017 17:12:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E5=8F=8D=E5=B0=84val?= =?UTF-8?q?ueOf=E8=BD=AC=E6=8D=A2=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../config/inject/AbstractInjectConfig.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 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 5c041c4..9ad7f35 100644 --- a/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java @@ -5,7 +5,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import org.bukkit.ChatColor; @@ -68,17 +67,10 @@ public abstract class AbstractInjectConfig { * @throws NoSuchMethodException * @throws SecurityException */ - private Object convertType(Class type, String path, Object value) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException, SecurityException { - switch (type.getName()) { - case "java.lang.Integer": - return Integer.valueOf(value.toString()); - } - if (type.isEnum()) { - try { - return Enum.valueOf(type, value.toString()); - } catch (IllegalArgumentException | NullPointerException ex) { - throw new ConfigParseException(String.format("值 %s 无效! %s 有效值为 %s", value, type.getSimpleName(), Arrays.toString(type.getEnumConstants()))); - } + private Object convertType(Class type, String path, Object value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + try { + return type.getDeclaredMethod("valueOf", String.class).invoke(null, value); + } catch (NoSuchMethodException | IllegalArgumentException ignored) { } if (InjectConfigurationSection.class.isAssignableFrom(type)) { if (config.isConfigurationSection(path)) {