mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 13:45:14 +01:00
Removed duplicate code
This commit is contained in:
parent
0e1ee335ea
commit
e3731994b3
@ -32,11 +32,10 @@ public class FileLister{
|
|||||||
* @param folderPath - folder path
|
* @param folderPath - folder path
|
||||||
* @param checkJar - if true, the jar will be checked
|
* @param checkJar - if true, the jar will be checked
|
||||||
* @return List of file names
|
* @return List of file names
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public List<String> list(String folderPath, boolean checkJar) throws IOException {
|
public List<String> list(String folderPath, boolean checkJar) throws IOException {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
// Check if the folder exists
|
// Check if the folder exists
|
||||||
File localeDir = new File(plugin.getDataFolder(), folderPath);
|
File localeDir = new File(plugin.getDataFolder(), folderPath);
|
||||||
if (localeDir.exists()) {
|
if (localeDir.exists()) {
|
||||||
@ -44,34 +43,7 @@ public class FileLister{
|
|||||||
return Arrays.asList(Objects.requireNonNull(localeDir.list(ymlFilter)));
|
return Arrays.asList(Objects.requireNonNull(localeDir.list(ymlFilter)));
|
||||||
} else if (checkJar) {
|
} else if (checkJar) {
|
||||||
// Else look in the JAR
|
// Else look in the JAR
|
||||||
File jarfile;
|
return listJar(folderPath);
|
||||||
|
|
||||||
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 result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user