diff --git a/src/main/java/com/josyf/macrobuttons/ConfigFile.java b/src/main/java/com/josyf/macrobuttons/ConfigFile.java index 8ec5d56..0641748 100644 --- a/src/main/java/com/josyf/macrobuttons/ConfigFile.java +++ b/src/main/java/com/josyf/macrobuttons/ConfigFile.java @@ -15,21 +15,18 @@ public class ConfigFile { static JSONParser parser = new JSONParser(); private static FileWriter fileWriter; - // if command.json exists, read it, convert it to an array, and append A JSON OBJECT + // Read commands.json, convert it to an array, and append A JSON OBJECT public static void appendToFile(JSONObject jsonObject) { try { Object obj = parser.parse(new FileReader("commands.json")); JSONArray array = (JSONArray) obj; array.add(jsonObject); writeToFile(array); - MacroButtons.initArray(); } catch (IOException e) { System.out.println("Commands.json doesn't exist. Creating one...!"); - // create json JSONArray jsonArray = new JSONArray(); jsonArray.add(jsonObject); writeToFile(jsonArray); - MacroButtons.initArray(); } catch (ParseException e) { e.printStackTrace(); } @@ -55,7 +52,7 @@ public class ConfigFile { } // parses commands.json into array, loop through array and add JSONObjects. returns array - public static ArrayList initArray() { + public static ArrayList getArrayFromJsonFile() { ArrayList commandObjects = new ArrayList<>(); try { // assign array to JSONArray using our commands.json as an object diff --git a/src/main/java/com/josyf/macrobuttons/MacroButtons.java b/src/main/java/com/josyf/macrobuttons/MacroButtons.java index 9a3d72d..12e9b6e 100644 --- a/src/main/java/com/josyf/macrobuttons/MacroButtons.java +++ b/src/main/java/com/josyf/macrobuttons/MacroButtons.java @@ -18,7 +18,7 @@ import java.util.ArrayList; public class MacroButtons implements ModInitializer { public static final String MOD_ID = "mgbuttons"; - public static ArrayList masterCommList; + private static ArrayList masterCommList; @Override public void onInitialize() { @@ -38,7 +38,6 @@ public class MacroButtons implements ModInitializer { ClientTickEvents.END_CLIENT_TICK.register(client -> { while (keyBinding.wasPressed()) { - System.out.println("Key 1 was pressed!"); MinecraftClient.getInstance().openScreen(new ButtonGUIScreen(new ButtonGUI())); //client.player.closeScreen(); } @@ -49,11 +48,12 @@ public class MacroButtons implements ModInitializer { MinecraftClient.getInstance().player.sendChatMessage(command); } - // Assign masterCommList to an array of JSON objects (from commands.json) + // Assign masterCommList to JSONArray (from commands.json). Runs once. static void initArray() { - masterCommList = ConfigFile.initArray(); + masterCommList = ConfigFile.getArrayFromJsonFile(); + // If commands.json doesn't exist yet, start a global list variable for future creation if (masterCommList == null) { - System.out.println("Error! Master Command List is null"); + setMasterCommList(new ArrayList<>()); } } diff --git a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java index 4dfbf3d..62c1b3b 100644 --- a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java +++ b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java @@ -62,7 +62,6 @@ public class ButtonGUI extends LightweightGuiDescription { WButton button = new WButton(new TranslatableText(name.getText())); button.setOnClick(() -> { - System.out.println("Command was " + instancedString); MacroButtons.runCommand(instancedString); }); @@ -75,17 +74,9 @@ public class ButtonGUI extends LightweightGuiDescription { ArrayList commListCopy = MacroButtons.getMasterCommList(); - if (commListCopy != null) { - commListCopy.add(newJsonObject); - - // Add jsonObject to commands.json - ConfigFile.appendToFile(newJsonObject); - - MacroButtons.setMasterCommList(commListCopy); - } else { - ConfigFile.appendToFile(newJsonObject); - } - + commListCopy.add(newJsonObject); + MacroButtons.setMasterCommList(commListCopy); + ConfigFile.appendToFile(newJsonObject); adjustBounds(); @@ -109,20 +100,11 @@ public class ButtonGUI extends LightweightGuiDescription { WButton button = new WButton(new TranslatableText(name)); button.setOnClick(() -> { - System.out.println("Command was " + instancedString); MacroButtons.runCommand(instancedString); }); - // int newX = incrementNumber(x, 4); - //System.out.println("x val: " + xValue); - //System.out.println("y val: " + yValue); - root.add(button, xValue, yValue, 4, 1); - - - adjustBounds(); - root.validate(this); } else { @@ -136,7 +118,6 @@ public class ButtonGUI extends LightweightGuiDescription { //JSONArray stringCommList = MacroButtons.masterCommList; ArrayList commListCopy = MacroButtons.getMasterCommList(); // Array will contain String class types. Convert these to objects - System.out.println("I be doin my thing here"); // Then convert the objects to buttons if (commListCopy != null) { for (int i = 0; i < commListCopy.size(); i++) {