From 7a703d216508f419b3c3c67e27d697c77725ad83 Mon Sep 17 00:00:00 2001 From: allenlol <1124796703@qq.com> Date: Tue, 2 Oct 2018 16:20:39 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20PluginUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 JavaPlugin 自带的 getFile 方法来获取插件文件 优化 --- .../me/skymc/taboolib/plugin/PluginUtils.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java index b1fb0a3..832b597 100644 --- a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java +++ b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java @@ -29,19 +29,14 @@ public class PluginUtils { PluginUtils() { } - public static File getPluginFile(Plugin plugin) { - for (File pluginFile : new File("plugins").listFiles()) { - if (pluginFile.getName().endsWith(".jar")) { - try { - PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(pluginFile); - if (desc.getName().equalsIgnoreCase(plugin.getName())) { - return pluginFile; - } - } catch (InvalidDescriptionException ignored) { - } - } + private File getPluginFile(JavaPlugin plugin) { + try { + Method method = JavaPlugin.class.getDeclaredMethod("getFile"); + method.setAccessible(true); + return (File) method.invoke(plugin); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not get plugin file", e); } - return null; } public static boolean isPluginExists(String name) {