diff --git a/src/main/java/net/dv8tion/discord/commands/KanzeTodoCommand.java b/src/main/java/net/dv8tion/discord/commands/KanzeTodoCommand.java index d51da07..2e6b595 100644 --- a/src/main/java/net/dv8tion/discord/commands/KanzeTodoCommand.java +++ b/src/main/java/net/dv8tion/discord/commands/KanzeTodoCommand.java @@ -110,7 +110,7 @@ private boolean markTodo(String arg, MessageReceivedEvent e) e.getTextChannel().sendMessageAsync(e.getAuthorNick() + ": No number was provided to mark! Example: `!!todo -3`", null); return false; } - int index ; + int index; try { index = Integer.valueOf(arg); @@ -128,6 +128,8 @@ private boolean markTodo(String arg, MessageReceivedEvent e) } int searchIndex = 1; + + listLoop: for (int i = 0; i < todoList.length(); i++) { JSONObject section = todoList.getJSONObject(i); @@ -139,7 +141,7 @@ private boolean markTodo(String arg, MessageReceivedEvent e) JSONObject entry = entries.getJSONObject(j); entry.put("marked", !entry.getBoolean("marked")); sendSectionToDiscord(section, index - j); - break; + break listLoop; } searchIndex++; } @@ -181,6 +183,7 @@ private boolean clearTodo() sendSectionToDiscord(section, index); index += section.getJSONArray("entries").length(); } + updateSaveFile(); return true; } @@ -256,13 +259,16 @@ private JSONObject createNewEntry(String content, boolean marked) private void updateSaveFile() { - try - { - Files.write(jsonFile.toPath(), todoList.toString(4).getBytes()); - } - catch (IOException e) + synchronized (todoList) { - e.printStackTrace(); + try + { + Files.write(jsonFile.toPath(), todoList.toString(4).getBytes()); + } + catch (IOException e) + { + e.printStackTrace(); + } } } @@ -299,6 +305,7 @@ private void sendSectionToDiscord(JSONObject section, int beginIndex) api.getTextChannelById(TODO_CHANNEL_ID).sendMessageAsync(sb.toString(), msg -> { section.put("messageId", msg.getId()); + updateSaveFile(); }); } else