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