read from file persists over client restarts
This commit is contained in:
parent
5c08c03a11
commit
1ed4e67237
@ -28,6 +28,8 @@ dependencies {
|
||||
|
||||
// Serialization
|
||||
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.56'
|
||||
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
|
||||
|
||||
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
|
@ -1,14 +1,24 @@
|
||||
package com.josyf.macrobuttons;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.josyf.macrobuttons.gui.ButtonGUI;
|
||||
import io.netty.channel.group.ChannelGroupFuture;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigFile {
|
||||
|
||||
private static FileWriter file;
|
||||
|
||||
static JSONParser parser = new JSONParser();
|
||||
|
||||
private static FileWriter fileWriter;
|
||||
private static FileReader fileReader;
|
||||
private static File file;
|
||||
//private static final String configSettings = ButtonGUI.getConfig();
|
||||
|
||||
public static void serializeCommand() {
|
||||
@ -23,7 +33,8 @@ public class ConfigFile {
|
||||
if (JSONConfig == null) {
|
||||
MacroButtons.sayMessage("GUI Configuration not yet initialized!");
|
||||
} else {
|
||||
String deserializedMessage = JSON.parseObject(JSONConfig, String.class);
|
||||
//String deserializedMessage = JSON.parseObject(JSONConfig, String.class);
|
||||
String deserializedMessage = readFile();
|
||||
MacroButtons.sayMessage(deserializedMessage);
|
||||
}
|
||||
}
|
||||
@ -31,19 +42,35 @@ public class ConfigFile {
|
||||
private static void writeToFile(String jsonMessage) {
|
||||
try {
|
||||
// these both write to the correct location
|
||||
file = new FileWriter("commands.json");
|
||||
fileWriter = new FileWriter("commands.json");
|
||||
// file = new FileWriter(MinecraftClient.getInstance().runDirectory + "/command.json");
|
||||
file.write(jsonMessage);
|
||||
fileWriter.write(jsonMessage);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
file.flush();
|
||||
file.close();
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String readFile() {
|
||||
try {
|
||||
Object obj = parser.parse(new FileReader("commands.json"));
|
||||
String jsonString = JSONObject.toJSONString(obj);
|
||||
System.out.println(jsonString);
|
||||
return jsonString;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "Not yet initialized yo";
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class ButtonGUI extends LightweightGuiDescription {
|
||||
int xValue = 0;
|
||||
int yValue = 1;
|
||||
|
||||
private static String ConfigSettings;
|
||||
private static String ConfigSettings = ConfigFile.readFile();
|
||||
|
||||
public ButtonGUI() {
|
||||
|
||||
@ -39,6 +39,13 @@ public class ButtonGUI extends LightweightGuiDescription {
|
||||
});
|
||||
root.add(button2, xValue + 2, yValue, 4, 1);
|
||||
|
||||
// read json file button
|
||||
WButton button3 = new WButton(new TranslatableText("Read command json"));
|
||||
button3.setOnClick(() -> {
|
||||
ConfigFile.readFile();
|
||||
});
|
||||
root.add(button3, xValue + 6, yValue + 2, 4, 1);
|
||||
|
||||
// Text GUI, not needed yet
|
||||
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
||||
// root.add(label, 0, 4, 2, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user