Skip to content

Commit

Permalink
➕ Better exception handler
Browse files Browse the repository at this point in the history
➕ Add the default exception handler for thread
  • Loading branch information
alwyn974 committed Aug 15, 2021
1 parent a11f02c commit feb4b75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "re.alwyn974"
version = "1.0.13"
version = "1.0.14"
archivesBaseName = "MinecraftBOT"

compileJava {
Expand All @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/re/alwyn974/minecraft/bot/MinecraftBOT.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* The heart of the MinecraftBOT
*
* @author <a href="https://github.com/alwyn974">Alwyn974</a>
* @version 1.0.13
* @version 1.0.14
* @since 1.0.0
*/
public class MinecraftBOT {
Expand All @@ -55,14 +55,18 @@ 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
new MCBOTFrame();
}

/**
* 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.");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +18,7 @@
* The Panel of the Gui
*
* @author <a href="https://github.com/alwyn974">Alwyn974</a>
* @version 1.0.13
* @version 1.0.14
* @since 1.0.0
*/
public class MCBOTPanel extends JPanel implements ActionListener {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit feb4b75

Please sign in to comment.