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

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
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 获得插件文件夹
*/