stop logging the disconnect and connect messages when too much

This commit is contained in:
Chayapak 2023-09-25 18:32:23 +07:00
parent dd7806d0f9
commit 65c79f9d9b

View file

@ -14,12 +14,23 @@ public class LoggerPlugin extends ChatPlugin.Listener {
public boolean logToConsole = true; public boolean logToConsole = true;
private int totalConnects = 0;
public LoggerPlugin(Bot bot) { public LoggerPlugin(Bot bot) {
this.bot = bot; this.bot = bot;
bot.addListener(new Bot.Listener() { bot.addListener(new Bot.Listener() {
@Override @Override
public void connecting() { public void connecting() {
totalConnects++;
if (totalConnects > 20) return;
else if (totalConnects == 20) {
log("Suspending connecting and disconnect messages from now on");
return;
}
log( log(
String.format( String.format(
"Connecting to: %s:%s", "Connecting to: %s:%s",
@ -39,6 +50,8 @@ public class LoggerPlugin extends ChatPlugin.Listener {
) )
); );
totalConnects = 0;
if (addedListener) return; if (addedListener) return;
bot.chat.addListener(LoggerPlugin.this); bot.chat.addListener(LoggerPlugin.this);
addedListener = true; addedListener = true;
@ -46,6 +59,8 @@ public class LoggerPlugin extends ChatPlugin.Listener {
@Override @Override
public void disconnected (DisconnectedEvent event) { public void disconnected (DisconnectedEvent event) {
if (totalConnects >= 20) return;
final Component reason = event.getReason(); final Component reason = event.getReason();
final String message = "Disconnected from " + bot.host + ":" + bot.port + ", reason: "; final String message = "Disconnected from " + bot.host + ":" + bot.port + ", reason: ";