优化 PluginUtils
使用 JavaPlugin 自带的 getFile 方法来获取插件文件 优化
This commit is contained in:
parent
c23f33526a
commit
7a703d2165
@ -29,19 +29,14 @@ public class PluginUtils {
|
|||||||
PluginUtils() {
|
PluginUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getPluginFile(Plugin plugin) {
|
private File getPluginFile(JavaPlugin plugin) {
|
||||||
for (File pluginFile : new File("plugins").listFiles()) {
|
|
||||||
if (pluginFile.getName().endsWith(".jar")) {
|
|
||||||
try {
|
try {
|
||||||
PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(pluginFile);
|
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
|
||||||
if (desc.getName().equalsIgnoreCase(plugin.getName())) {
|
method.setAccessible(true);
|
||||||
return pluginFile;
|
return (File) method.invoke(plugin);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new RuntimeException("Could not get plugin file", e);
|
||||||
}
|
}
|
||||||
} catch (InvalidDescriptionException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPluginExists(String name) {
|
public static boolean isPluginExists(String name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user