mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI.git
synced 2024-12-30 21:07:42 +01:00
Added method to get all class files of a certain type from a specific jar
This commit is contained in:
parent
d0445e231d
commit
adca215ea7
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user