mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-24 02:08:48 +00:00
feat: 添加直接获取注入配置
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
543eb0db84
commit
d04e1e47a3
@ -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 获得插件文件夹
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user