From a5359b705afe2f59879928795606035777baf311 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 25 Apr 2023 13:40:14 +0700 Subject: [PATCH] add reconnect delay to each bot option (optional) --- .idea/workspace.xml | 27 +++++++++---------- .../chipmunk/chayapak/chomens_bot/Bot.java | 3 ++- .../chayapak/chomens_bot/Configuration.java | 3 ++- src/main/resources/default-config.yml | 7 +++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9e421021..79ef0d8e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,12 +4,11 @@ - @@ -484,7 +482,8 @@ - diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index e98217de..c7ee52f2 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -69,6 +69,7 @@ public class Bot { this.port = botOption.port; this.options = botOption; + if (options.reconnectDelay == -1) options.reconnectDelay = config.reconnectDelay; this.allBots = allBots; @@ -172,7 +173,7 @@ public class Bot { public void disconnected(DisconnectedEvent disconnectedEvent) { loggedIn = false; - int reconnectDelay = config.reconnectDelay(); + int reconnectDelay = options.reconnectDelay(); final String stringMessage = ComponentUtilities.stringify(disconnectedEvent.getReason()); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java index 7cd61462..65806295 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -14,7 +14,7 @@ public class Configuration { @Getter public Map consolePrefixes; - @Getter public int reconnectDelay = 7000; + @Getter public int reconnectDelay = 2000; @Getter public Map keys; @@ -83,5 +83,6 @@ public class Configuration { @Getter @Setter public boolean useCore = true; @Getter @Setter public boolean useChat = false; @Getter public boolean hasEssentials = true; + @Getter public int reconnectDelay = -1; } } diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 2f7be75d..90646c06 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -61,14 +61,16 @@ selfCare: prefix: true username: true # do NOT set this to false unless you know what you are doing bots: - # username, kaboom, useCore, useChat and hasEssentials are optional. + # username, kaboom, useCore, useChat, hasEssentials and reconnectDelay are optional. + # more info: # for username if it doesn't exist it will default to random username # for kaboom it will just default to `false` - # for serverName name it whatever you like, it will be used as server name in trusted broadcast + # for serverName name it whatever you like, it will be used as server name in trusted broadcast and in console # for useCore it just sends the command using chat instead of using core. recommended to enable useChat too when this is enabled # for useChat when the bot sends output (tellraw) it will chat instead of using the core to run tellraw # for hasEssentials it is self-explanatory. if the server has essentials plugin just set it to true + # for reconnectDelay if not specified it will just default to the global reconnectDelay - host: 'localhost' port: 25565 @@ -78,3 +80,4 @@ bots: useCore: true useChat: false hasEssentials: false + reconnectDelay: 2000