mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 05:17:05 +02:00
Added method to get all class files of a certain type from a specific jar
This commit is contained in:
@@ -20,8 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.util;
|
package me.clip.placeholderapi.util;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -30,22 +28,27 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
|
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
public static List<Class<?>> getClasses(String folder, Class<?> type) {
|
public static List<Class<?>> getClasses(String folder, Class<?> type) {
|
||||||
|
return getClasses(folder, null, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Class<?>> getClasses(String folder, String fileName, Class<?> type) {
|
||||||
List<Class<?>> list = new ArrayList<>();
|
List<Class<?>> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
if (!f.mkdir()) {
|
|
||||||
PlaceholderAPIPlugin.getInstance().getLogger().severe("Failed to create " + folder + " folder!");
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
FilenameFilter fileNameFilter = (dir, name) -> {
|
FilenameFilter fileNameFilter = (dir, name) -> {
|
||||||
int i = name.lastIndexOf('.');
|
if (fileName != null) {
|
||||||
return i > 0 && name.substring(i).equals(".jar");
|
return name.endsWith(".jar") && name.replace(".jar", "")
|
||||||
|
.equalsIgnoreCase(fileName.replace(".jar", ""));
|
||||||
|
}
|
||||||
|
return name.endsWith(".jar");
|
||||||
};
|
};
|
||||||
File[] jars = f.listFiles(fileNameFilter);
|
File[] jars = f.listFiles(fileNameFilter);
|
||||||
if (jars == null) {
|
if (jars == null) {
|
||||||
@@ -55,7 +58,8 @@ public class FileUtil {
|
|||||||
list = gather(file.toURI().toURL(), list, type);
|
list = gather(file.toURI().toURL(), list, type);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
} catch (Throwable t) {}
|
} catch (Throwable t) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user