From feb4b750dc7af9e442f014faee1fca09ac7b0d0e Mon Sep 17 00:00:00 2001 From: Alwyn Mattapullut Date: Sun, 15 Aug 2021 15:50:26 +0400 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Better=20exception=20handler=20?= =?UTF-8?q?=E2=9E=95=20Add=20the=20default=20exception=20handler=20for=20t?= =?UTF-8?q?hread?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 12 ++++++------ .../java/re/alwyn974/minecraft/bot/MinecraftBOT.java | 8 ++++++-- .../re/alwyn974/minecraft/bot/gui/MCBOTPanel.java | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 7aff8e1..695900f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = "re.alwyn974" -version = "1.0.13" +version = "1.0.14" archivesBaseName = "MinecraftBOT" compileJava { @@ -26,14 +26,14 @@ repositories { } dependencies { - testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0" + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' implementation "com.github.Steveice10:MCProtocolLib:-SNAPSHOT" - implementation "commons-cli:commons-cli:+" + implementation 'commons-cli:commons-cli:1.4' implementation "re.alwyn974:logger:1.0.0" - implementation "org.reflections:reflections:+" - implementation "com.formdev:flatlaf:1.2" //this is magic :o + implementation 'org.reflections:reflections:0.9.12' + implementation 'com.formdev:flatlaf:1.5' //this is magic :o } test { diff --git a/src/main/java/re/alwyn974/minecraft/bot/MinecraftBOT.java b/src/main/java/re/alwyn974/minecraft/bot/MinecraftBOT.java index dd537fe..015488e 100644 --- a/src/main/java/re/alwyn974/minecraft/bot/MinecraftBOT.java +++ b/src/main/java/re/alwyn974/minecraft/bot/MinecraftBOT.java @@ -33,7 +33,7 @@ * The heart of the MinecraftBOT * * @author Alwyn974 - * @version 1.0.13 + * @version 1.0.14 * @since 1.0.0 */ public class MinecraftBOT { @@ -55,6 +55,10 @@ public class MinecraftBOT { */ public static void main(String... args) { registerCommands(); + Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { + throwable.printStackTrace(); + MinecraftBOT.getLogger().error("Error: %s", throwable.toString()); + }); if (GraphicsEnvironment.isHeadless() || args.length > 0) runHeadless(args); else @@ -62,7 +66,7 @@ public static void main(String... args) { } /** - * Register all of the command located in re.alwyn974.minecraft.bot.cmd + * Register all the command located in re.alwyn974.minecraft.bot.cmd */ private static void registerCommands() { Reflections reflections = new Reflections("re.alwyn974.minecraft.bot.cmd."); diff --git a/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java b/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java index d6b5f31..47a5b01 100644 --- a/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java +++ b/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java @@ -1,6 +1,5 @@ package re.alwyn974.minecraft.bot.gui; -import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import re.alwyn974.logger.LoggerFactory; import re.alwyn974.minecraft.bot.MinecraftBOT; @@ -19,7 +18,7 @@ * The Panel of the Gui * * @author Alwyn974 - * @version 1.0.13 + * @version 1.0.14 * @since 1.0.0 */ public class MCBOTPanel extends JPanel implements ActionListener { @@ -128,8 +127,9 @@ public void actionPerformed(ActionEvent e) { bot = new EntityBOT(hostField.getText(), Integer.parseInt(portField.getText()), usernameField.getText(), new String(passwordField.getPassword()), debugBox.isSelected(), autoReconnectBox.isSelected()); try { bot.connect(); - } catch (RequestException ex) { - MinecraftBOT.getLogger().error("Can't authenticate", ex); + } catch (Exception ex) { + MinecraftBOT.getLogger().error("Error: %s", ex.getMessage()); + ex.printStackTrace(); setFieldsEnabled(true); botThread.interrupt(); }