mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35: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 {
|
try {
|
||||||
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
||||||
// We cannot use Bukkit's saveResource, because we want it to go into a specific folder, so...
|
// 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
|
||||||
// Get the last part of the name
|
int lastIndex = name.lastIndexOf('/');
|
||||||
int lastIndex = name.lastIndexOf('/');
|
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
|
||||||
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
|
if (DEBUG) {
|
||||||
if (DEBUG) {
|
plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath());
|
||||||
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) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage());
|
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