From efd837db36b8aeeef09595dcd990319b3e68ad84 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:08:25 +0700 Subject: [PATCH] fix: tick plugin breaking when there's an exception --- .../chomens_bot/plugins/DiscordPlugin.java | 4 +++- .../chomens_bot/plugins/TickPlugin.java | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java index c0223d1..3ffac41 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -86,7 +86,9 @@ public class DiscordPlugin { bot.tick.addListener(new TickPlugin.Listener() { @Override public void onAlwaysTick () { - onDiscordTick(channelId); + try { + onDiscordTick(channelId); + } catch (Exception ignored) {} } }); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/TickPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/TickPlugin.java index 4f2fbe0..0a019e5 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/TickPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/TickPlugin.java @@ -18,11 +18,25 @@ public class TickPlugin { } private void tick () { - for (Listener listener : listeners) listener.onAlwaysTick(); + for (Listener listener : listeners) { + try { + listener.onAlwaysTick(); + } catch (Exception e) { + bot.logger.error("Caught exception in an always tick listener!"); + e.printStackTrace(); + } + } if (!bot.loggedIn) return; - for (Listener listener : listeners) listener.onTick(); + for (Listener listener : listeners) { + try { + listener.onTick(); + } catch (Exception e) { + bot.logger.error("Caught exception in a tick listener!"); + e.printStackTrace(); + } + } } public void addListener (Listener listener) {