From 2178dac54f2555548560399f32717fe51b474624 Mon Sep 17 00:00:00 2001 From: ProSavage Date: Sun, 11 Nov 2018 20:05:57 -0600 Subject: [PATCH] Add migrator for players.json file, so leaders will not be lost when upgrading to new version --- .../massivecraft/factions/SavageFactions.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/com/massivecraft/factions/SavageFactions.java b/src/main/java/com/massivecraft/factions/SavageFactions.java index b2c6af4c..28a50639 100644 --- a/src/main/java/com/massivecraft/factions/SavageFactions.java +++ b/src/main/java/com/massivecraft/factions/SavageFactions.java @@ -37,6 +37,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; +import java.io.*; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.*; @@ -143,6 +144,7 @@ public class SavageFactions extends MPlugin { changeItemIDSInConfig(); } setupMultiversionMaterials(); + migrateFPlayerLeaders(); log("==== End Setup ===="); if (!preEnable()) { @@ -305,6 +307,34 @@ public class SavageFactions extends MPlugin { } } + private void migrateFPlayerLeaders() { + List lines = new ArrayList(); + File fplayerFile = new File("plugins\\Factions\\players.json"); + try { + BufferedReader br = new BufferedReader(new FileReader(fplayerFile)); + System.out.println("Migrating old players.json file."); + + String line; + while ((line = br.readLine()) != null) { + if (line.contains("\"role\": \"ADMIN\"")) { + line = line.replace("\"role\": \"ADMIN\"", "\"role\": " + "\"LEADER\""); + } + lines.add(line); + } + br.close(); + BufferedWriter bw = new BufferedWriter(new FileWriter(fplayerFile)); + for (String newLine : lines) { + bw.write(newLine + "\n"); + } + bw.flush(); + bw.close(); + } catch (IOException ex) { + System.out.println("File was not found for players.json, assuming" + + " there is no need to migrate old players.json file."); + } + + + } private void changeItemIDSInConfig() {