Merge remote-tracking branch 'origin/master'

This commit is contained in:
坏黑 2018-10-03 15:23:56 +08:00
commit 6b45d144c2

View File

@ -9,6 +9,8 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap; import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.plugin.*; import org.bukkit.plugin.*;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Method;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -30,18 +32,13 @@ public class PluginUtils {
} }
public static File getPluginFile(Plugin plugin) { public static File getPluginFile(Plugin plugin) {
for (File pluginFile : new File("plugins").listFiles()) { try {
if (pluginFile.getName().endsWith(".jar")) { Method method = plugin.getClass().getDeclaredMethod("getFile");
try { method.setAccessible(true);
PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(pluginFile); return (File) method.invoke(plugin);
if (desc.getName().equalsIgnoreCase(plugin.getName())) { } catch (ReflectiveOperationException e) {
return pluginFile; 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) {