Removed duplicate code

This commit is contained in:
tastybento 2018-06-23 19:19:53 -07:00
parent 0e1ee335ea
commit e3731994b3

View File

@ -32,11 +32,10 @@ public class FileLister{
* @param folderPath - folder path
* @param checkJar - if true, the jar will be checked
* @return List of file names
*/
public List<String> list(String folderPath, boolean checkJar) throws IOException {
List<String> result = new ArrayList<>();
// Check if the folder exists
File localeDir = new File(plugin.getDataFolder(), folderPath);
if (localeDir.exists()) {
@ -44,34 +43,7 @@ public class FileLister{
return Arrays.asList(Objects.requireNonNull(localeDir.list(ymlFilter)));
} else if (checkJar) {
// Else look in the JAR
File jarfile;
try {
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
method.setAccessible(true);
jarfile = (File) method.invoke(plugin);
} catch (Exception e) {
throw new IOException(e);
}
JarFile jar = new JarFile(jarfile);
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String path = entry.getName();
if (!path.startsWith(folderPath)) {
continue;
}
if (entry.getName().endsWith(".yml")) {
result.add(entry.getName());
}
}
jar.close();
return listJar(folderPath);
}
return result;
}