From d365eb498b52e18632e4d80b628a18e3ae4cc463 Mon Sep 17 00:00:00 2001 From: Intelli Date: Fri, 18 Feb 2022 20:47:18 -0700 Subject: [PATCH] Re-sort language file after upgrading --- .../net/coreprotect/config/ConfigFile.java | 22 +++++++++++++++++++ .../coreprotect/patch/script/__2_21_0.java | 1 + 2 files changed, 23 insertions(+) diff --git a/src/main/java/net/coreprotect/config/ConfigFile.java b/src/main/java/net/coreprotect/config/ConfigFile.java index 439dfb1..34da1ad 100644 --- a/src/main/java/net/coreprotect/config/ConfigFile.java +++ b/src/main/java/net/coreprotect/config/ConfigFile.java @@ -14,6 +14,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -204,6 +205,27 @@ public class ConfigFile extends Config { } } + public static void sortFile(String fileName) { + try { + Path path = Paths.get(ConfigHandler.path + fileName); + List lines = Files.readAllLines(path); + List sort = lines.subList(2, lines.size()); + Collections.sort(sort); + lines = lines.subList(0, 2); + lines.addAll(sort); + + if (lines.size() > 0) { + String lastLine = lines.get(lines.size() - 1); // append the final line to prevent a line separator from being added + Files.write(path, (lines.remove(lines.size() - 1).isEmpty() ? lines : lines), StandardCharsets.UTF_8); + Files.write(path, lastLine.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); + lines.clear(); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + public static void resetCache(String cacheName, String fileName) throws IOException { File file = new File(CoreProtect.getInstance().getDataFolder(), cacheName); if (file.length() > 0) { diff --git a/src/main/java/net/coreprotect/patch/script/__2_21_0.java b/src/main/java/net/coreprotect/patch/script/__2_21_0.java index 69121bf..fe8dd4b 100644 --- a/src/main/java/net/coreprotect/patch/script/__2_21_0.java +++ b/src/main/java/net/coreprotect/patch/script/__2_21_0.java @@ -37,6 +37,7 @@ public class __2_21_0 { ConfigFile.modifyLine("language.yml", "LOOKUP_VIEW_PAGE: \"To view a page, type \\\"{0}\\\".\"", null); ConfigFile.modifyLine("language.yml", "PREVIEW_CONTAINER: \"You can't preview container transactions.\"", null); + ConfigFile.sortFile("language.yml"); } catch (Exception e) { e.printStackTrace();