fix: tick plugin breaking when there's an exception

This commit is contained in:
Chayapak 2024-11-19 18:08:25 +07:00
parent e4970cc56b
commit efd837db36
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
2 changed files with 19 additions and 3 deletions

View file

@ -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) {}
}
});

View file

@ -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) {