From 147620f3d6150847fc8704e723f077e88bc96fba Mon Sep 17 00:00:00 2001 From: thmsdy Date: Fri, 15 Feb 2019 01:07:34 -0600 Subject: [PATCH] Add port config option and add bot feedback message --- src/main/java/com/fpghoti/bcraftbot/Main.java | 8 +++++++- src/main/java/com/fpghoti/bcraftbot/bot/BotListener.java | 4 +++- .../com/fpghoti/bcraftbot/bot/command/AddMeCommand.java | 1 + .../java/com/fpghoti/bcraftbot/sql/MySQLConnection.java | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fpghoti/bcraftbot/Main.java b/src/main/java/com/fpghoti/bcraftbot/Main.java index 5fc040a..930f145 100644 --- a/src/main/java/com/fpghoti/bcraftbot/Main.java +++ b/src/main/java/com/fpghoti/bcraftbot/Main.java @@ -22,6 +22,7 @@ import net.dv8tion.jda.core.entities.User; public class Main extends JavaPlugin { private String sqlhost; + private String sqlport; private String sqluser; private String sqldatabase; private String sqlpassword; @@ -48,7 +49,7 @@ public class Main extends JavaPlugin { messageSet(); getSettings(); getServer().getPluginManager().registerEvents(new PlayerListener(this), this); - sql = new MySQLConnection(this,sqlhost,sqluser,sqlpassword,sqldatabase); + sql = new MySQLConnection(this,sqlhost,sqlport,sqluser,sqlpassword,sqldatabase); sql.connect(); if(!sql.tableExists(sqltable)){ log(Level.INFO, "Table not found. Creating new table..."); @@ -99,6 +100,10 @@ public class Main extends JavaPlugin { config.createSection("Host"); config.set("Host", "0.0.0.0"); } + if (config.get("Port") == null){ + config.createSection("Port"); + config.set("Port", "3306"); + } if (config.get("User") == null){ config.createSection("User"); config.set("User", "username"); @@ -144,6 +149,7 @@ public class Main extends JavaPlugin { public void getSettings(){ sqlhost = config.getString("Host"); + sqlport = config.getString("Port"); sqluser = config.getString("User"); sqlpassword = config.getString("Password"); sqldatabase = config.getString("Database"); diff --git a/src/main/java/com/fpghoti/bcraftbot/bot/BotListener.java b/src/main/java/com/fpghoti/bcraftbot/bot/BotListener.java index 5014ff2..5a99409 100644 --- a/src/main/java/com/fpghoti/bcraftbot/bot/BotListener.java +++ b/src/main/java/com/fpghoti/bcraftbot/bot/BotListener.java @@ -3,6 +3,8 @@ package com.fpghoti.bcraftbot.bot; import java.util.logging.Level; import com.fpghoti.bcraftbot.bot.ServerBot; + +import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.events.ReadyEvent; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import net.dv8tion.jda.core.hooks.ListenerAdapter; @@ -17,7 +19,7 @@ public class BotListener extends ListenerAdapter{ @Override public void onMessageReceived(MessageReceivedEvent event){ - if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith("!") && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){ + if(event.getChannelType() == ChannelType.TEXT && !event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith("!") && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){ bot.handleCommand(bot.getCommandParser().parse(event.getMessage().getContentRaw().toLowerCase(), event)); } } diff --git a/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java b/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java index ed101bf..258861a 100644 --- a/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java +++ b/src/main/java/com/fpghoti/bcraftbot/bot/command/AddMeCommand.java @@ -36,6 +36,7 @@ public class AddMeCommand implements Command{ }else { bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + name + "\');"); } + event.getChannel().sendMessage("Updating Minecraft user database with username **" + args[0] + "**.").queue(); } } diff --git a/src/main/java/com/fpghoti/bcraftbot/sql/MySQLConnection.java b/src/main/java/com/fpghoti/bcraftbot/sql/MySQLConnection.java index ca0d4a6..29e0a2e 100644 --- a/src/main/java/com/fpghoti/bcraftbot/sql/MySQLConnection.java +++ b/src/main/java/com/fpghoti/bcraftbot/sql/MySQLConnection.java @@ -15,13 +15,15 @@ public class MySQLConnection{ private Connection connection; private String host; + private String port; private String user; private String password; private String database; - public MySQLConnection(Main plugin, String sqlhost, String sqluser, String sqlpassword, String sqldatabase) { + public MySQLConnection(Main plugin, String sqlhost, String sqlport, String sqluser, String sqlpassword, String sqldatabase) { this.plugin = plugin; this.host = sqlhost; + this.port = sqlport; this.user = sqluser; this.password = sqlpassword; this.database = sqldatabase; @@ -75,7 +77,7 @@ public class MySQLConnection{ catch (Exception e){} connection = null; try{ - connection = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, user, password); + connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password); } catch (Exception e){ plugin.log(Level.SEVERE, "There was an issue with MySQL: " + e.getMessage());