diff --git a/src/main/java/com/jagrosh/jmusicbot/Bot.java b/src/main/java/com/jagrosh/jmusicbot/Bot.java index 65db398bf..6041e2669 100644 --- a/src/main/java/com/jagrosh/jmusicbot/Bot.java +++ b/src/main/java/com/jagrosh/jmusicbot/Bot.java @@ -46,12 +46,12 @@ public class Bot private final NowplayingHandler nowplaying; private final AloneInVoiceHandler aloneInVoiceHandler; private final YoutubeOauth2TokenHandler youTubeOauth2TokenHandler; + private final GUI gui; private boolean shuttingDown = false; private JDA jda; - private GUI gui; - public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings) + public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings, GUI gui) { this.waiter = waiter; this.config = config; @@ -66,6 +66,7 @@ public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings) this.nowplaying.init(); this.aloneInVoiceHandler = new AloneInVoiceHandler(this); this.aloneInVoiceHandler.init(); + this.gui = gui; } public BotConfig getConfig() @@ -161,9 +162,4 @@ public void setJDA(JDA jda) { this.jda = jda; } - - public void setGUI(GUI gui) - { - this.gui = gui; - } } diff --git a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java index 30409a6bf..2e2ad7ddb 100644 --- a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java +++ b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java @@ -82,28 +82,15 @@ private static void startBot() config.load(); if(!config.isValid()) return; - LOG.info("Loaded config from " + config.getConfigLocation()); - // set log level from config - ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel( - Level.toLevel(config.getLogLevel(), Level.INFO)); - - // set up the listener - EventWaiter waiter = new EventWaiter(); - SettingsManager settings = new SettingsManager(); - Bot bot = new Bot(waiter, config, settings); - CommandClient client = createCommandClient(config, settings, bot); - + GUI gui = null; if(!prompt.isNoGUI()) { - try + try { - GUI gui = new GUI(bot); - bot.setGUI(gui); + gui = new GUI(); gui.init(); - - LOG.info("Loaded config from " + config.getConfigLocation()); } catch(Exception e) { @@ -113,6 +100,21 @@ private static void startBot() } } + LOG.info("Loaded config from " + config.getConfigLocation()); + + // set log level from config + ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel( + Level.toLevel(config.getLogLevel(), Level.INFO)); + + // set up the listener + EventWaiter waiter = new EventWaiter(); + SettingsManager settings = new SettingsManager(); + Bot bot = new Bot(waiter, config, settings, gui); + if (gui != null) + gui.setBot(bot); + CommandClient client = createCommandClient(config, settings, bot); + + // attempt to log in and start try { diff --git a/src/main/java/com/jagrosh/jmusicbot/gui/GUI.java b/src/main/java/com/jagrosh/jmusicbot/gui/GUI.java index e3f47ae7a..6e8ecab2e 100644 --- a/src/main/java/com/jagrosh/jmusicbot/gui/GUI.java +++ b/src/main/java/com/jagrosh/jmusicbot/gui/GUI.java @@ -30,15 +30,18 @@ public class GUI extends JFrame { private final ConsolePanel console; - private final Bot bot; + private Bot bot; - public GUI(Bot bot) + public GUI() { super(); - this.bot = bot; console = new ConsolePanel(); } + public void setBot(Bot bot) { + this.bot = bot; + } + public void init() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); @@ -56,7 +59,8 @@ public void init() { try { - bot.shutdown(); + if (bot != null) + bot.shutdown(); } catch(Exception ex) {