fix: do not write to the locale file if nothing changed when updating it

Something in that mess of a code the charset gets lost or something
and breaks special characters like `prefix: '&f'`

So we just don't save the changes for now if nothing changed ^^
The system where locales are currently fetched for
merging with the existing one is abandoned anyway,
so I don't think there are any changes that would be merged
This commit is contained in:
Christian Koop 2024-06-26 23:41:04 +02:00
parent dcc71e7ba9
commit 2bcaee34aa
No known key found for this signature in database
GPG Key ID: 6A4A09E8ED946113

View File

@ -15,10 +15,10 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -204,13 +204,13 @@ public class Locale {
return updateFiles(plugin, in, destinationFile, builtin); return updateFiles(plugin, in, destinationFile, builtin);
} }
try (OutputStream outputStream = Files.newOutputStream(destinationFile.toPath())) { try {
copy(in, outputStream); Files.copy(in, destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
fileName = fileName.substring(0, fileName.lastIndexOf('.')); fileName = fileName.substring(0, fileName.lastIndexOf('.'));
return fileName.split("_").length == 2; return fileName.split("_").length == 2;
} catch (IOException ignore) { } catch (IOException ex) {
ex.printStackTrace();
} }
return false; return false;
@ -273,9 +273,6 @@ public class Locale {
existingLang.save(); existingLang.save();
} }
existingLang.setRootNodeSpacing(0);
existingLang.save();
return !added.isEmpty(); return !added.isEmpty();
} catch (InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
plugin.getLogger().log(Level.SEVERE, "Error checking config " + existingFile.getName(), ex); plugin.getLogger().log(Level.SEVERE, "Error checking config " + existingFile.getName(), ex);
@ -481,17 +478,4 @@ public class Locale {
public String getName() { public String getName() {
return this.name; return this.name;
} }
private static void copy(InputStream input, OutputStream output) {
int n;
byte[] buffer = new byte[1024 * 4];
try {
while ((n = input.read(buffer)) != -1) {
output.write(buffer, 0, n);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
} }