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;
import com.github.jsixface.YamlConfig;
import de.studiocode.invui.util.IOUtils;
import net.artelnatif.nicko.NickoBukkit;
import org.yaml.snakeyaml.Yaml;
import java.io.*;
import java.util.HashMap;
public class LocaleFileManager {
private final Yaml yaml = new Yaml();
@ -25,15 +25,18 @@ public class LocaleFileManager {
public boolean dumpFromLocale(Locale locale) {
if (locale == Locale.CUSTOM) 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 {
if (folder.mkdirs()) {
if (file.createNewFile()) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
yaml.dump(values, writer);
try (FileOutputStream outputStream = new FileOutputStream(file)) {
IOUtils.copy(inputStream, outputStream, 8192);
}
}
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}