Re-sort language file after upgrading

This commit is contained in:
Intelli 2022-02-18 20:47:18 -07:00
parent 585d8b275a
commit d365eb498b
2 changed files with 23 additions and 0 deletions

View File

@ -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<String> lines = Files.readAllLines(path);
List<String> 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) {

View File

@ -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();