Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 2178dac

Browse files
committed
Add migrator for players.json file, so leaders will not be lost when upgrading to new version
1 parent 1ccf419 commit 2178dac

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/main/java/com/massivecraft/factions/SavageFactions.java

+30
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.bukkit.plugin.Plugin;
3838
import org.bukkit.plugin.RegisteredServiceProvider;
3939

40+
import java.io.*;
4041
import java.lang.reflect.Modifier;
4142
import java.lang.reflect.Type;
4243
import java.util.*;
@@ -143,6 +144,7 @@ public void run() {
143144
changeItemIDSInConfig();
144145
}
145146
setupMultiversionMaterials();
147+
migrateFPlayerLeaders();
146148
log("==== End Setup ====");
147149

148150
if (!preEnable()) {
@@ -305,6 +307,34 @@ private void setupPlaceholderAPI() {
305307
}
306308
}
307309

310+
private void migrateFPlayerLeaders() {
311+
List<String> lines = new ArrayList<String>();
312+
File fplayerFile = new File("plugins\\Factions\\players.json");
313+
try {
314+
BufferedReader br = new BufferedReader(new FileReader(fplayerFile));
315+
System.out.println("Migrating old players.json file.");
316+
317+
String line;
318+
while ((line = br.readLine()) != null) {
319+
if (line.contains("\"role\": \"ADMIN\"")) {
320+
line = line.replace("\"role\": \"ADMIN\"", "\"role\": " + "\"LEADER\"");
321+
}
322+
lines.add(line);
323+
}
324+
br.close();
325+
BufferedWriter bw = new BufferedWriter(new FileWriter(fplayerFile));
326+
for (String newLine : lines) {
327+
bw.write(newLine + "\n");
328+
}
329+
bw.flush();
330+
bw.close();
331+
} catch (IOException ex) {
332+
System.out.println("File was not found for players.json, assuming"
333+
+ " there is no need to migrate old players.json file.");
334+
}
335+
336+
337+
}
308338

309339
private void changeItemIDSInConfig() {
310340

0 commit comments

Comments
 (0)