Add in PlayerSave.java
Code:
public static void updateCharString(String charName, String lineContains, String replaceWith) {
String filePath = "./data/characters/"+charName+".txt";
try {
FileReader charFile = new FileReader(filePath);
BufferedReader br = new BufferedReader(charFile);
String line1 = br.readLine();
while (line1 != null) {
if (line1.trim().contains(lineContains)) {
line1 = replaceWith;
}
BufferedWriter out = new BufferedWriter(new FileWriter(filePath + ".tmp", true));
out.write(line1);
out.newLine();
out.close();
line1 = br.readLine();
}
br.close();
charFile.close();
} catch (Exception e) {
e.printStackTrace();
}
File file = new File(filePath);
file.delete();
File file2 = new File(filePath + ".tmp");
file2.renameTo(file);
}
Usage:
PlayerSave.updateCharString("arrowzftw, "special-amount", "special-amount = 100");
What this will do is replace all lines that contain special-amount with special-amount = 100
So if i had in my file:
special-amount = 10000;
It'll be replaced with:
special-amount = 100
Useful for something like an automated lottery.