From 9f674f2d1fc015a9709c04a17ac9d866aee12a6b Mon Sep 17 00:00:00 2001 From: Joseph Garcia Date: Fri, 18 Dec 2020 15:22:53 -0600 Subject: [PATCH] remove bloat code --- .../com/josyf/macrobuttons/CommandObject.java | 7 -- .../com/josyf/macrobuttons/ConfigFile.java | 81 ------------------- .../com/josyf/macrobuttons/gui/ButtonGUI.java | 42 ---------- 3 files changed, 130 deletions(-) delete mode 100644 src/main/java/com/josyf/macrobuttons/CommandObject.java diff --git a/src/main/java/com/josyf/macrobuttons/CommandObject.java b/src/main/java/com/josyf/macrobuttons/CommandObject.java deleted file mode 100644 index c0acaf1..0000000 --- a/src/main/java/com/josyf/macrobuttons/CommandObject.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.josyf.macrobuttons; - -public class CommandObject { - - public CommandObject(String name, String command) { - } -} diff --git a/src/main/java/com/josyf/macrobuttons/ConfigFile.java b/src/main/java/com/josyf/macrobuttons/ConfigFile.java index ec59e58..8ec5d56 100644 --- a/src/main/java/com/josyf/macrobuttons/ConfigFile.java +++ b/src/main/java/com/josyf/macrobuttons/ConfigFile.java @@ -2,9 +2,6 @@ package com.josyf.macrobuttons; import com.alibaba.fastjson.JSON; import com.cedarsoftware.util.io.JsonWriter; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.josyf.macrobuttons.gui.ButtonGUI; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -15,49 +12,9 @@ import java.util.ArrayList; public class ConfigFile { - static JSONParser parser = new JSONParser(); - private static FileWriter fileWriter; - public static void serializeCommand() { - // CREATE OBJECT - CommandObject newCommand = new CommandObject("Say hello", "hello command"); - - // add new object to config - appendToFile(newCommand); - } - - public static void loadSerialization() { - String JSONConfig = ButtonGUI.getConfig(); - if (JSONConfig == null) { - MacroButtons.runCommand("GUI Configuration not yet initialized!"); - } else { - System.out.println(readFile()); - } - } - - // if commands.json exists, read it, convert it to an array, and append - // DEPRECATED PROBABLY DELETABLE - private static void appendToFile(CommandObject commandObject) { - JSONArray jsonArray = new JSONArray(); - try { - // if commands.json exists, read it, convert it to an array, and append - Object obj = parser.parse(new FileReader("commands.json")); - - JSONArray array = (JSONArray) obj; - JSONObject obj2 = (JSONObject)array.get(0); - - } catch (IOException e) { - System.out.println("Commands.json doesn't exist. Creating one..."); - // create json - jsonArray.add(commandObject); - writeToFile(jsonArray); - } catch (ParseException e) { - System.out.println("Something went wrong |o|"); - } - } - // if command.json exists, read it, convert it to an array, and append A JSON OBJECT public static void appendToFile(JSONObject jsonObject) { try { @@ -119,42 +76,4 @@ public class ConfigFile { } return null; } - - // DEPRECATED CAN PROBABLY DELETE - private static void writeToFile(String jsonMessage) { - try { - // these both write to the correct location - fileWriter = new FileWriter("commands.json"); - // file = new FileWriter(MinecraftClient.getInstance().runDirectory + "/command.json"); - System.out.println("APPENDING!"); - - fileWriter.write(jsonMessage); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - fileWriter.flush(); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static String readFile() { - try { - Object obj = parser.parse(new FileReader("commands.json")); - String jsonString = obj.toString(); - //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"; - } } diff --git a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java index 3c31dc0..4dfbf3d 100644 --- a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java +++ b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java @@ -17,63 +17,21 @@ public class ButtonGUI extends LightweightGuiDescription { int xValue = 0; int yValue = 1; - private static String ConfigSettings = ConfigFile.readFile(); - public ButtonGUI() { // initialize root panel of GUI WGridPanel root = new WGridPanel(); - setupBackground(root); - // ######### DEBUG BUTTONS ############ - // example button to create config JSON - WButton button = new WButton(new TranslatableText("Serialize")); - button.setOnClick(() -> { - ConfigFile.serializeCommand(); - }); - root.add(button, xValue, yValue + 9, 4, 1); - - // example load serialization button - WButton button2 = new WButton(new TranslatableText("Load Serialization")); - button2.setOnClick(() -> { - ConfigFile.loadSerialization(); - }); - root.add(button2, xValue + 4, yValue + 9, 6, 1); - - // read json file button - WButton button3 = new WButton(new TranslatableText("Read command json")); - button3.setOnClick(() -> { - ConfigFile.readFile(); - }); - root.add(button3, xValue + 10, yValue + 9, 6, 1); - - - // read mastercommlist - // read json file button - WButton button4 = new WButton(new TranslatableText("Read master list")); - button4.setOnClick(() -> { - System.out.println(MacroButtons.getMasterCommList()); - }); - root.add(button4, xValue + 10, yValue + 8, 6, 1); - - // ######### DEBUG BUTTONS ############ - // Text GUI, not needed yet // WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF); // root.add(label, 0, 4, 2, 1); addSavedButtons(root); - addCommandSection(root); - root.validate(this); } - public static String getConfig() { - return ConfigSettings; - } - private void addCommandSection(WGridPanel root) { // Add text field for command NAME entry WTextField nameTextField = new WTextField();