mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 21:27:44 +01:00
Code smells cleanup
Extract nested try block into a separate method.
This commit is contained in:
parent
180517cef3
commit
a9ea8e830d
@ -79,20 +79,13 @@ public final class LocalesManager {
|
||||
try {
|
||||
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
||||
// We cannot use Bukkit's saveResource, because we want it to go into a specific folder, so...
|
||||
try (InputStream initialStream = plugin.getResource(name)) {
|
||||
// Get the last part of the name
|
||||
int lastIndex = name.lastIndexOf('/');
|
||||
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath());
|
||||
}
|
||||
if (!targetFile.exists()) {
|
||||
java.nio.file.Files.copy(initialStream, targetFile.toPath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage());
|
||||
}
|
||||
|
||||
copyFile(name, targetFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage());
|
||||
@ -124,4 +117,16 @@ public final class LocalesManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFile(String name, File targetFile) {
|
||||
try (InputStream initialStream = plugin.getResource(name)) {
|
||||
if (!targetFile.exists()) {
|
||||
java.nio.file.Files.copy(initialStream, targetFile.toPath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user