Performance Improvements (#340)

* Performance Improvements

* More Optimizations

* Even More Optimizations & Cleanups

* Almost a recode I guess
This commit is contained in:
Crypto Morin
2020-07-16 09:32:22 -07:00
committed by GitHub
parent f9f59f1f96
commit 54d5757d0a
52 changed files with 876 additions and 875 deletions

View File

@@ -42,65 +42,50 @@ public class FileUtil {
try {
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
if (!f.exists()) {
return list;
}
if (!f.exists()) return list;
FilenameFilter fileNameFilter = (dir, name) -> {
boolean isJar = name.endsWith(".jar");
if (fileName != null) {
return name.endsWith(".jar") && name.replace(".jar", "")
.equalsIgnoreCase(fileName.replace(".jar", ""));
return isJar && name.substring(0, name.length() - 4)
.equalsIgnoreCase(fileName.substring(0, fileName.length() - 4));
}
return name.endsWith(".jar");
return isJar;
};
File[] jars = f.listFiles(fileNameFilter);
if (jars == null) {
return list;
}
if (jars == null) return list;
for (File file : jars) {
list = gather(file.toURI().toURL(), list, type);
}
return list;
} catch (Throwable t) {
} catch (Throwable ignored) {
}
return null;
}
private static List<Class<?>> gather(URL jar, List<Class<?>> list, Class<?> clazz) {
if (list == null) {
list = new ArrayList<>();
}
// list cannot be null.
try (URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
JarInputStream jis = new JarInputStream(jar.openStream())) {
while (true) {
JarEntry j = jis.getNextJarEntry();
if (j == null) {
break;
}
String name = j.getName();
if (name == null || name.isEmpty()) {
continue;
}
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
String name = entry.getName();
if (name == null || name.isEmpty()) continue;
if (name.endsWith(".class")) {
name = name.replace("/", ".");
String cname = name.substring(0, name.lastIndexOf(".class"));
name = name.substring(0, name.length() - 6).replace('/', '.');
Class<?> c = cl.loadClass(cname);
if (clazz.isAssignableFrom(c)) {
list.add(c);
}
Class<?> loaded = cl.loadClass(name);
if (clazz.isAssignableFrom(loaded)) list.add(loaded);
}
}
} catch (Throwable t) {
} catch (Throwable ignored) {
}
return list;