feat: 添加直接获取注入配置

Signed-off-by: 502647092 <admin@yumc.pw>
merge/1/MERGE
502647092 2016-12-16 18:12:49 +08:00
parent 543eb0db84
commit d04e1e47a3
1 changed files with 29 additions and 4 deletions

View File

@ -1,13 +1,15 @@
package pw.yumc.YumCore.bukkit;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Logger;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.lang.reflect.Field;
import java.util.logging.Logger;
/**
* Instance
*
@ -19,6 +21,10 @@ public class P {
*
*/
public static JavaPlugin instance;
/**
*
*/
public static Method getInjectConfigMethod;
static {
Object pluginClassLoader = P.class.getClassLoader();
@ -29,6 +35,11 @@ public class P {
} catch (Exception e) {
e.printStackTrace();
}
try {
getInjectConfigMethod = instance.getClass().getMethod("get" + instance.getName() + "Config");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
/**
@ -51,6 +62,20 @@ public class P {
return (FC) instance.getConfig();
}
/**
* @param <FC>
*
* @return
*/
@SuppressWarnings("unchecked")
public static <FC> FC getInjectConfig() {
try {
return (FC) getInjectConfigMethod.invoke(instance);
} catch (IllegalAccessException | InvocationTargetException ignored) {
}
return getConfig();
}
/**
* @return
*/