fix: custom lang file not being copied over

This commit is contained in:
aro 2023-01-12 11:34:29 +01:00
parent f63c82a01f
commit 5fbcdf5de2

View file

@ -1,11 +1,11 @@
package net.artelnatif.nicko.i18n; package net.artelnatif.nicko.i18n;
import com.github.jsixface.YamlConfig; import com.github.jsixface.YamlConfig;
import de.studiocode.invui.util.IOUtils;
import net.artelnatif.nicko.NickoBukkit; import net.artelnatif.nicko.NickoBukkit;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.*; import java.io.*;
import java.util.HashMap;
public class LocaleFileManager { public class LocaleFileManager {
private final Yaml yaml = new Yaml(); private final Yaml yaml = new Yaml();
@ -25,15 +25,18 @@ public class LocaleFileManager {
public boolean dumpFromLocale(Locale locale) { public boolean dumpFromLocale(Locale locale) {
if (locale == Locale.CUSTOM) return true; if (locale == Locale.CUSTOM) return true;
if (file.exists()) return true; if (file.exists()) return true;
final HashMap<String, String> values = yaml.load(this.getClass().getClassLoader().getResourceAsStream(locale.getCode() + ".yml")); final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(locale.getCode() + ".yml");
try { try {
if (file.createNewFile()) { if (folder.mkdirs()) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { if (file.createNewFile()) {
yaml.dump(values, writer); try (FileOutputStream outputStream = new FileOutputStream(file)) {
IOUtils.copy(inputStream, outputStream, 8192);
}
} }
} }
return true; return true;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
return false; return false;
} }
} }