From 9b824e195a1f4d7d1fda7afcad7848875ea194e7 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 16 Nov 2024 13:07:53 +0700 Subject: [PATCH] "fix": my try on fixing the login spam (no work) --- .../java/me/chayapak1/chomens_bot/Main.java | 7 ++++--- .../chomens_bot/plugins/FilterPlugin.java | 8 ++++--- .../util/PersistentDataUtilities.java | 21 ++++++++++--------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/Main.java b/src/main/java/me/chayapak1/chomens_bot/Main.java index 9b1dede..d773c23 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Main.java +++ b/src/main/java/me/chayapak1/chomens_bot/Main.java @@ -84,6 +84,9 @@ public class Main { config = yaml.load(reader); + PersistentDataUtilities.init(); + ComponentUtilities.stringify(Component.empty()); // best way to initialize the class 2024 + executor.scheduleAtFixedRate(() -> { try { checkInternet(); @@ -158,9 +161,7 @@ public class Main { bots.add(bot); } - // fards - ComponentUtilities.stringify(Component.empty()); // best way to initialize the class 2024 - + // fard new ConsolePlugin(bots, config, jda); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/FilterPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/FilterPlugin.java index ae8d1ce..1b6ccfd 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/FilterPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/FilterPlugin.java @@ -96,11 +96,13 @@ public class FilterPlugin extends PlayersPlugin.Listener { @Override public void playerJoined (PlayerEntry target) { - final FilteredPlayer player = getPlayer(target.profile.getName()); + bot.executorService.submit(() -> { + final FilteredPlayer player = getPlayer(target.profile.getName()); - if (player == null) return; + if (player == null) return; - doAll(target); + doAll(target); + }); } @Override diff --git a/src/main/java/me/chayapak1/chomens_bot/util/PersistentDataUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/PersistentDataUtilities.java index a4fb30d..a3ac141 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/PersistentDataUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/PersistentDataUtilities.java @@ -4,6 +4,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import me.chayapak1.chomens_bot.Main; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -21,11 +22,7 @@ public class PersistentDataUtilities { private static boolean stopping = false; - static { - init(); - } - - private static void init () { + public static void init () { try { if (!Files.exists(path)) Files.createFile(path); @@ -47,12 +44,16 @@ public class PersistentDataUtilities { private static void write (String string) { if (stopping) return; // is this necessary? - try { - writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + Main.executorService.submit(() -> { + try { + writer.close(); - writer.write(string); - writer.flush(); - } catch (IOException ignored) {} + writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + + writer.write(string); + writer.flush(); + } catch (IOException ignored) {} + }); } public static void stop () {