Skip to content

Commit

Permalink
return as sortedset
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Mar 28, 2024
1 parent d19fb2d commit 30b5924
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,21 @@ public void reloadLang() {
}
}

private List<String> getAvailableTranslations() {
private SortedSet<String> getAvailableTranslations() {
try (final JarFile pluginJar = new JarFile(getFile())) {
final File langDirectory = new File(getDataFolder() + "/lang");
Files.createDirectories(langDirectory.toPath());
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirectory.listFiles()).map(File::getName))
.distinct()
.map(name -> {
final Matcher matcher = langPattern.matcher(name);
return matcher.find() ? matcher.group(1) : null;
})
.filter(Objects::nonNull)
.sorted()
.collect(Collectors.toList());
.collect(Collectors.toCollection(TreeSet::new));
} catch (Throwable t) {
logger.error("Failed querying for available translations!", t);
return Collections.emptyList();
return new TreeSet<>();
}
}
}

0 comments on commit 30b5924

Please sign in to comment.