Add port config option and add bot feedback message

This commit is contained in:
Ghoti 2019-02-15 01:07:34 -06:00
parent 5b9fb5548e
commit 147620f3d6
4 changed files with 15 additions and 4 deletions

View File

@ -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");

View File

@ -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));
}
}

View File

@ -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();
}
}

View File

@ -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());