Search in sources :

Example 1 with TownyLoadedDatabaseEvent

use of com.palmergames.bukkit.towny.event.TownyLoadedDatabaseEvent in project Towny by TownyAdvanced.

the class TownyUniverse method loadDatabase.

/**
 * Loads the database into memory.
 *
 * @param loadDbType - load setting from the config.
 * @return true when the database will load.
 */
private boolean loadDatabase(String loadDbType) {
    long startTime = System.currentTimeMillis();
    /*
         * Select the datasource.
         */
    switch(loadDbType.toLowerCase()) {
        case "ff":
        case "flatfile":
            {
                this.dataSource = new TownyFlatFileSource(towny, this);
                break;
            }
        case "mysql":
            {
                this.dataSource = new TownySQLSource(towny, this);
                break;
            }
        default:
            {
                throw new TownyInitException("Database: Database.yml unsupported load format: " + loadDbType, TownyInitException.TownyError.DATABASE_CONFIG);
            }
    }
    /*
         * Load the actual database.
         */
    if (!dataSource.loadAll())
        throw new TownyInitException("Database: Failed to load database.", TownyInitException.TownyError.DATABASE);
    long time = System.currentTimeMillis() - startTime;
    towny.getLogger().info("Database: Loaded in " + time + "ms.");
    // TODO: remove this when we're using UUIDs directly in the database.
    towny.getLogger().info("Database: " + TownySettings.getUUIDPercent() + " of residents have stored UUIDs.");
    // Throw Event.
    Bukkit.getPluginManager().callEvent(new TownyLoadedDatabaseEvent());
    // Congratulations the Database loaded.
    return true;
}
Also used : TownySQLSource(com.palmergames.bukkit.towny.db.TownySQLSource) TownyLoadedDatabaseEvent(com.palmergames.bukkit.towny.event.TownyLoadedDatabaseEvent) TownyFlatFileSource(com.palmergames.bukkit.towny.db.TownyFlatFileSource) TownyInitException(com.palmergames.bukkit.towny.exceptions.initialization.TownyInitException)

Aggregations

TownyFlatFileSource (com.palmergames.bukkit.towny.db.TownyFlatFileSource)1 TownySQLSource (com.palmergames.bukkit.towny.db.TownySQLSource)1 TownyLoadedDatabaseEvent (com.palmergames.bukkit.towny.event.TownyLoadedDatabaseEvent)1 TownyInitException (com.palmergames.bukkit.towny.exceptions.initialization.TownyInitException)1