Fixed MySQL Database initiation.

Issue was sent on Spigot Discussion.
Fixed typo that was causing it.
This commit is contained in:
Rsl1122 2017-01-21 09:19:25 +02:00
parent 048c201bd6
commit 45279da849
5 changed files with 71 additions and 53 deletions

View File

@ -63,21 +63,21 @@ public class Plan extends JavaPlugin {
databases.add(new MySQLDB(this));
databases.add(new SQLiteDB(this));
for (Database database : databases) {
String name = database.getConfigName();
ConfigurationSection section = getConfig().getConfigurationSection(name);
if (section == null) {
section = getConfig().createSection(name);
}
database.getConfigDefaults(section);
if (section.getKeys(false).isEmpty()) {
getConfig().set(name, null);
}
}
// for (Database database : databases) {
// String name = database.getConfigName();
//
// ConfigurationSection section = getConfig().getConfigurationSection(name);
//
// if (section == null) {
// section = getConfig().createSection(name);
// }
//
// database.getConfigDefaults(section);
//
// if (section.getKeys(false).isEmpty()) {
// getConfig().set(name, null);
// }
// }
getConfig().options().copyDefaults(true);

View File

@ -6,6 +6,8 @@ import org.bukkit.configuration.ConfigurationSection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.bukkit.configuration.file.FileConfiguration;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
*
@ -29,54 +31,55 @@ public class MySQLDB extends SQLDB {
*/
@Override
protected Connection getNewConnection() {
ConfigurationSection config = getConfigSection();
setUserName(config.getString("tables.users"));
setLocationName(config.getString("tables.locations"));
setNicknamesName(config.getString("tables.nicknames"));
setGamemodetimesName(config.getString("tables.gamemodes"));
setIpsName(config.getString("tables.ips"));
setCommanduseName(config.getString("tables.commandusages"));
setServerdataName(config.getString("tables.serverdata"));
FileConfiguration config = getPlugin(Plan.class).getConfig();
setUserName(config.getString("mysql.tables.users"));
setLocationName(config.getString("mysql.tables.locations"));
setNicknamesName(config.getString("mysql.tables.nicknames"));
setGamemodetimesName(config.getString("mysql.tables.gamemodetimes"));
setIpsName(config.getString("mysql.tables.ips"));
setCommanduseName(config.getString("mysql.tables.commandusages"));
setServerdataName(config.getString("mysql.tables.serverdata"));
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://" + config.getString("host") + ":" + config.getString("port") + "/" + config.getString("database");
String url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getString("mysql.port") + "/" + config.getString("mysql.database");
return DriverManager.getConnection(url, config.getString("user"), config.getString("password"));
return DriverManager.getConnection(url, config.getString("mysql.user"), config.getString("mysql.password"));
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return null;
}
}
private ConfigurationSection getSection(ConfigurationSection parent, String childName) {
ConfigurationSection child = parent.getConfigurationSection(childName);
if (child == null) {
child = parent.createSection(childName);
}
return child;
}
// private ConfigurationSection getSection(ConfigurationSection parent, String childName) {
// ConfigurationSection child = parent.getConfigurationSection(childName);
//
// if (child == null) {
// child = parent.createSection(childName);
// }
//
// return child;
// }
@Override
public void getConfigDefaults(ConfigurationSection section) {
section.addDefault("host", "localhost");
section.addDefault("port", 3306);
section.addDefault("user", "root");
section.addDefault("password", "minecraft");
section.addDefault("database", "Plan");
ConfigurationSection tables = getSection(section, "tables");
tables.addDefault("users", "plan_users");
tables.addDefault("locations", "plan_locations");
tables.addDefault("nicknames", "plan_nicknames");
tables.addDefault("gamemodetimes", "plan_gamemodetimes");
tables.addDefault("ips", "plan_ips");
tables.addDefault("commandusages", "plan_commandusages");
tables.addDefault("serverdata", "plan_serverdata");
// section.addDefault("host", "localhost");
// section.addDefault("port", 3306);
// section.addDefault("user", "root");
// section.addDefault("password", "minecraft");
// section.addDefault("database", "Plan");
//
// ConfigurationSection tables = getSection(section, "tables");
//
// tables.addDefault("users", "plan_users");
// tables.addDefault("locations", "plan_locations");
// tables.addDefault("nicknames", "plan_nicknames");
// tables.addDefault("gamemodetimes", "plan_gamemodetimes");
// tables.addDefault("ips", "plan_ips");
// tables.addDefault("commandusages", "plan_commandusages");
// tables.addDefault("serverdata", "plan_serverdata");
}
@Override

View File

@ -27,7 +27,7 @@ import static org.bukkit.Bukkit.getOfflinePlayer;
public abstract class SQLDB extends Database {
private final Plan plugin;
final Plan plugin;
private final boolean supportsModification;

View File

@ -46,4 +46,19 @@ Customization:
IgnoreWhen: 'sure, think, with, are, you'
database:
type: sqlite
type: sqlite
mysql:
host: localhost
port: 3306
user: root
password: minecraft
database: Plan
tables:
users: plan_users
locations: plan_locations
nicknames: plan_nicknames
gamemodetimes: plan_gamemodetimes
ips: plan_ips
commandusages: plan_commandusages
serverdata: plan_serverdata

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: com.djrapitops.plan.Plan
version: 2.1.2
version: 2.1.3
commands:
plan: