Add port config option and add bot feedback message
This commit is contained in:
		
							parent
							
								
									5b9fb5548e
								
							
						
					
					
						commit
						147620f3d6
					
				| 
						 | 
					@ -22,6 +22,7 @@ import net.dv8tion.jda.core.entities.User;
 | 
				
			||||||
public class Main extends JavaPlugin {
 | 
					public class Main extends JavaPlugin {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private String sqlhost;
 | 
						private String sqlhost;
 | 
				
			||||||
 | 
						private String sqlport;
 | 
				
			||||||
	private String sqluser;
 | 
						private String sqluser;
 | 
				
			||||||
	private String sqldatabase;
 | 
						private String sqldatabase;
 | 
				
			||||||
	private String sqlpassword;
 | 
						private String sqlpassword;
 | 
				
			||||||
| 
						 | 
					@ -48,7 +49,7 @@ public class Main extends JavaPlugin {
 | 
				
			||||||
		messageSet();
 | 
							messageSet();
 | 
				
			||||||
		getSettings();
 | 
							getSettings();
 | 
				
			||||||
		getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
 | 
							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();
 | 
							sql.connect();
 | 
				
			||||||
		if(!sql.tableExists(sqltable)){
 | 
							if(!sql.tableExists(sqltable)){
 | 
				
			||||||
			log(Level.INFO, "Table not found. Creating new table...");
 | 
								log(Level.INFO, "Table not found. Creating new table...");
 | 
				
			||||||
| 
						 | 
					@ -99,6 +100,10 @@ public class Main extends JavaPlugin {
 | 
				
			||||||
			config.createSection("Host");
 | 
								config.createSection("Host");
 | 
				
			||||||
			config.set("Host", "0.0.0.0");
 | 
								config.set("Host", "0.0.0.0");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (config.get("Port") == null){
 | 
				
			||||||
 | 
								config.createSection("Port");
 | 
				
			||||||
 | 
								config.set("Port", "3306");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if (config.get("User") == null){
 | 
							if (config.get("User") == null){
 | 
				
			||||||
			config.createSection("User");
 | 
								config.createSection("User");
 | 
				
			||||||
			config.set("User", "username");
 | 
								config.set("User", "username");
 | 
				
			||||||
| 
						 | 
					@ -144,6 +149,7 @@ public class Main extends JavaPlugin {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void getSettings(){
 | 
						public void getSettings(){
 | 
				
			||||||
		sqlhost = config.getString("Host");
 | 
							sqlhost = config.getString("Host");
 | 
				
			||||||
 | 
							sqlport = config.getString("Port");
 | 
				
			||||||
		sqluser = config.getString("User");
 | 
							sqluser = config.getString("User");
 | 
				
			||||||
		sqlpassword = config.getString("Password");
 | 
							sqlpassword = config.getString("Password");
 | 
				
			||||||
		sqldatabase = config.getString("Database");
 | 
							sqldatabase = config.getString("Database");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,8 @@ package com.fpghoti.bcraftbot.bot;
 | 
				
			||||||
import java.util.logging.Level;
 | 
					import java.util.logging.Level;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.fpghoti.bcraftbot.bot.ServerBot;
 | 
					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.ReadyEvent;
 | 
				
			||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
 | 
					import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
 | 
				
			||||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
 | 
					import net.dv8tion.jda.core.hooks.ListenerAdapter;
 | 
				
			||||||
| 
						 | 
					@ -17,7 +19,7 @@ public class BotListener extends ListenerAdapter{
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onMessageReceived(MessageReceivedEvent event){
 | 
						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));
 | 
								bot.handleCommand(bot.getCommandParser().parse(event.getMessage().getContentRaw().toLowerCase(), event));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,7 @@ public class AddMeCommand implements Command{
 | 
				
			||||||
			}else {
 | 
								}else {
 | 
				
			||||||
				bot.getSQL().update("INSERT INTO " + bot.getTableName() + " (DiscordID,MinecraftName) VALUES (\'" + event.getAuthor().getId() + "\',\'" + name + "\');");
 | 
									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();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,13 +15,15 @@ public class MySQLConnection{
 | 
				
			||||||
	private Connection connection;
 | 
						private Connection connection;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private String host;
 | 
						private String host;
 | 
				
			||||||
 | 
						private String port;
 | 
				
			||||||
	private String user;
 | 
						private String user;
 | 
				
			||||||
	private String password;
 | 
						private String password;
 | 
				
			||||||
	private String database;
 | 
						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.plugin = plugin;
 | 
				
			||||||
		this.host = sqlhost;
 | 
							this.host = sqlhost;
 | 
				
			||||||
 | 
							this.port = sqlport;
 | 
				
			||||||
		this.user = sqluser;
 | 
							this.user = sqluser;
 | 
				
			||||||
		this.password = sqlpassword;
 | 
							this.password = sqlpassword;
 | 
				
			||||||
		this.database = sqldatabase;
 | 
							this.database = sqldatabase;
 | 
				
			||||||
| 
						 | 
					@ -75,7 +77,7 @@ public class MySQLConnection{
 | 
				
			||||||
		catch (Exception e){}
 | 
							catch (Exception e){}
 | 
				
			||||||
		connection = null;
 | 
							connection = null;
 | 
				
			||||||
		try{
 | 
							try{
 | 
				
			||||||
			connection = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, user, password);
 | 
								connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		catch (Exception e){
 | 
							catch (Exception e){
 | 
				
			||||||
			plugin.log(Level.SEVERE, "There was an issue with MySQL: " + e.getMessage());
 | 
								plugin.log(Level.SEVERE, "There was an issue with MySQL: " + e.getMessage());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue