diff --git a/src/main/java/com/josyf/macrobuttons/ConfigFile.java b/src/main/java/com/josyf/macrobuttons/ConfigFile.java index 93a9f17..00fa512 100644 --- a/src/main/java/com/josyf/macrobuttons/ConfigFile.java +++ b/src/main/java/com/josyf/macrobuttons/ConfigFile.java @@ -77,10 +77,9 @@ public class ConfigFile { public static void addObjectToCommList(JSONObject jsonObject) { ArrayList commListCopy = MacroButtons.getMasterCommList(); - if (commListCopy.size() <= 20) { - commListCopy.add(jsonObject); - MacroButtons.setMasterCommList(commListCopy); - } - + commListCopy.add(jsonObject); + MacroButtons.setMasterCommList(commListCopy); } + + } diff --git a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java index 7f94089..368c150 100644 --- a/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java +++ b/src/main/java/com/josyf/macrobuttons/gui/ButtonGUI.java @@ -35,6 +35,7 @@ public class ButtonGUI extends LightweightGuiDescription { private void addCommandSection(WGridPanel root) { // Add text field for command NAME entry WTextField nameTextField = new WTextField(); + nameTextField.setMaxLength(10); nameTextField.setSuggestion("Name"); root.add(nameTextField, 0, 12, 6, 1); @@ -57,23 +58,25 @@ public class ButtonGUI extends LightweightGuiDescription { // Only add the button if there are contents in both if (!name.getText().equals("") && !command.getText().equals("")) { - String commandString = command.getText(); - WButton button = new WButton(new TranslatableText(name.getText())); - button.setOnClick(() -> { - MacroButtons.runCommand(commandString); - }); - root.add(button, xValue, yValue, 4, 1); + if (!isListTooLong()) { + String commandString = command.getText(); + WButton button = new WButton(new TranslatableText(name.getText())); + button.setOnClick(() -> { + MacroButtons.runCommand(commandString); + }); + root.add(button, xValue, yValue, 4, 1); - // Create a new Json object & append to masterCommList - JSONObject newJsonObject = new JSONObject(); - newJsonObject.put("name", name.getText()); - newJsonObject.put("command", command.getText()); + // Create a new Json object & append to masterCommList + JSONObject newJsonObject = new JSONObject(); + newJsonObject.put("name", name.getText()); + newJsonObject.put("command", command.getText()); - // append the buttons to masterList for future loading - ConfigFile.addObjectToCommList(newJsonObject); - ConfigFile.appendToFile(newJsonObject); + // append the buttons to masterList for future loading + ConfigFile.addObjectToCommList(newJsonObject); + ConfigFile.appendToFile(newJsonObject); - adjustBounds(); + adjustBounds(); + } name.setText(""); command.setText(""); @@ -127,6 +130,10 @@ public class ButtonGUI extends LightweightGuiDescription { } } + private boolean isListTooLong() { + return MacroButtons.getMasterCommList().size() > 19; + } + // Change background panel color to transparent black @Override public void addPainters() {