diff --git a/shared/src/main/java/me/neznamy/tab/shared/config/file/ConfigurationFile.java b/shared/src/main/java/me/neznamy/tab/shared/config/file/ConfigurationFile.java index 87b917c9f..63b84b3ef 100644 --- a/shared/src/main/java/me/neznamy/tab/shared/config/file/ConfigurationFile.java +++ b/shared/src/main/java/me/neznamy/tab/shared/config/file/ConfigurationFile.java @@ -51,7 +51,6 @@ protected ConfigurationFile(@Nullable InputStream source, @NonNull File destinat if (source == null) throw new IllegalStateException("File does not exist and source is null"); Files.copy(source, file.toPath()); } - detectHeader(); } /** @@ -373,40 +372,6 @@ private String getRealKey(@NonNull Map map, @NonNull String key) { return key; } - /** - * Detects header of a file (first lines of file starting with #). - * - * @throws IOException - * if I/O operation fails - */ - private void detectHeader() throws IOException { - header = new ArrayList<>(); - for (String line : Files.readAllLines(file.toPath())) { - if (line.startsWith("#")) { - header.add(line); - } else { - break; - } - } - } - - /** - * Inserts header back into file. This is required after calling {@link #save()}, because - * it destroys the header. - * - * @throws IOException - * if I/O operation fails - */ - public void fixHeader() throws IOException { - if (header == null) return; - List content = new ArrayList<>(header); - content.addAll(Files.readAllLines(file.toPath())); - Files.delete(file.toPath()); - if (file.createNewFile()) { - Files.write(file.toPath(), content); - } - } - /** * Sets value to specified key if key does not exist. * diff --git a/shared/src/main/java/me/neznamy/tab/shared/config/file/YamlConfigurationFile.java b/shared/src/main/java/me/neznamy/tab/shared/config/file/YamlConfigurationFile.java index 6f65c4a2c..3a0999faf 100644 --- a/shared/src/main/java/me/neznamy/tab/shared/config/file/YamlConfigurationFile.java +++ b/shared/src/main/java/me/neznamy/tab/shared/config/file/YamlConfigurationFile.java @@ -63,16 +63,15 @@ public YamlConfigurationFile(@Nullable InputStream source, @NonNull File destina } @Override - public void save() { + public synchronized void save() { try { Writer writer = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); new Yaml(options).dump(values, writer); writer.close(); - fixHeader(); } catch (IOException e) { - TAB.getInstance().getPlatform().logWarn(TabComponent.fromColoredText("Failed to save yaml file " + file.getPath() + " with content " + values.toString())); + TAB.getInstance().getPlatform().logWarn(TabComponent.fromColoredText("Failed to save yaml file " + file.getPath() + " with content " + values.toString() + ": " + e.getMessage())); } } } \ No newline at end of file