package eltik.endran.hippo; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; public class Core extends JavaPlugin { FileConfiguration config = getConfig(); private Connection connection; public String host, database, username, password, table; public int port; public void mysqlSetup() { // CREDIT TO TheSourceCode host = this.getConfig().getString("host"); port = this.getConfig().getInt("port"); database = this.getConfig().getString("database"); username = this.getConfig().getString("username"); password = this.getConfig().getString("password"); table = this.getConfig().getString("table"); try { synchronized (this) { if (getConnection() != null && !getConnection().isClosed()) { return; } Class.forName("com.mysql.jdbc.Driver"); setConnection( DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password)); Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Connected to SQL database."); } } catch (SQLException e) { Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Unable to connect to SQL database."); e.printStackTrace(); } catch (ClassNotFoundException e) { Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Unable to connect to SQL database."); e.printStackTrace(); } } // Gets the connection. public Connection getConnection() { return connection; } // Sets the connection. public void setConnection(Connection connection) { this.connection = connection; } // Loading config public void loadConfig(){ // Copy everything from the config.yml to the actual file in the folder. getConfig().options().copyDefaults(true); saveDefaultConfig(); } }