package com.simplyian.easydb;

import com.simplyian.easydb.command.DBReloadCommand;
import java.util.logging.Level;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * EasyDBPlugin Main class.
 */
public class EasyDBPlugin extends JavaPlugin {
    private Database db;

    @Override
    public void onEnable() {
        // Make sure the config has been made
        saveDefaultConfig();

        EasyDB.setInstance(this);
        reloadDb();

        getCommand("dbreload").setExecutor(new DBReloadCommand(this));

        if (!db.isValid()) {
            getLogger().log(Level.WARNING, "Database credentials are invalid. Please check your credentials and run /dbreload.");
        } else {
            getLogger().log(Level.INFO, "Connected to database at " + db.getSource().getServerName() + ":" + db.getSource().getPort() + " successfully.");
        }
        getLogger().log(Level.INFO, "Plugin loaded.");
    }

    @Override
    public void onDisable() {
        EasyDB.setInstance(null);
        getLogger().log(Level.INFO, "Plugin unloaded.");
    }

    /**
     * Loads the database.
     */
    public void reloadDb() {
        String dbUser = getConfig().getString("db.user");
        String dbPass = getConfig().getString("db.pass", "");
        String dbHost = getConfig().getString("db.host");
        int dbPort = getConfig().getInt("db.port");
        String dbName = getConfig().getString("db.name");
        db = new Database(this, dbUser, dbPass, dbHost, dbPort, dbName);
    }

    /**
     * Gets the database.
     *
     * @return
     */
    public Database getDb() {
        return db;
    }
}

@@ -109,16 +109,70 @@
 .Level;%0A
+import org.bukkit.configuration.ConfigurationSection;%0A
 import o
@@ -1190,57 +1190,160 @@
     
-String dbUser = getConfig().getString(%22db.user%22);
+ConfigurationSection s = getConfig().getConfigurationSection(%22db%22);%0A        if (s == null) %7B%0A            s = getConfig().createSection(%22db%22);%0A        %7D%0A
 %0A   
@@ -1360,26 +1360,61 @@
 g db
-Pass
+User
  = 
+s.
 get
-Config()
+String(%22user%22);%0A        String dbPass = s
 .get
@@ -1421,19 +1421,16 @@
 String(%22
-db.
 pass%22, %22
@@ -1453,35 +1453,25 @@
 ng dbHost = 
-getConfig()
+s
 .getString(%22
@@ -1470,19 +1470,16 @@
 String(%22
-db.
 host%22);%0A
@@ -1499,27 +1499,17 @@
 bPort = 
-getConfig()
+s
 .getInt(
@@ -1509,19 +1509,16 @@
 getInt(%22
-db.
 port%22);%0A
@@ -1541,27 +1541,17 @@
 bName = 
-getConfig()
+s
 .getStri
@@ -1554,19 +1554,16 @@
 String(%22
-db.
 name%22);%0A

Use ConfigurationSection for database info.