Search in sources :

Example 1 with PrefixGlobalUpdateRequest

use of net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest in project FunnyGuilds by FunnyGuilds.

the class DatabaseBasic method load.

public void load() {
    Database db = Database.getInstance();
    PluginConfig config = Settings.getConfig();
    usersTable(db);
    regionsTable(db);
    guildsTable(db);
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.usersTableName + "`", usersResult -> {
        try {
            while (usersResult.next()) {
                User user = DatabaseUser.deserialize(usersResult);
                if (user != null) {
                    user.changed();
                }
            }
            FunnyLogger.info("Loaded users: " + UserUtils.getUsers().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    if (Settings.getConfig().regionsEnabled) {
        Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.regionsTableName + "`", regionsResult -> {
            try {
                while (regionsResult.next()) {
                    Region region = DatabaseRegion.deserialize(regionsResult);
                    if (region != null) {
                        region.changed();
                    }
                }
                FunnyLogger.info("Loaded regions: " + RegionUtils.getRegions().size());
            } catch (Exception e) {
                if (FunnyLogger.exception(e.getCause())) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        FunnyLogger.info("Regions are disabled and thus - not loaded");
    }
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.guildsTableName + "`", guildsResult -> {
        try {
            while (guildsResult.next()) {
                Guild guild = DatabaseGuild.deserialize(guildsResult);
                if (guild != null) {
                    guild.changed();
                }
            }
            FunnyLogger.info("Loaded guilds: " + GuildUtils.getGuilds().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    // TODO
    for (Guild guild : GuildUtils.getGuilds()) {
        if (guild.getOwner() != null) {
            continue;
        }
        GuildUtils.deleteGuild(guild);
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalUpdateRequest());
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Region(net.dzikoysk.funnyguilds.basic.Region) Guild(net.dzikoysk.funnyguilds.basic.Guild) SQLException(java.sql.SQLException) PrefixGlobalUpdateRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)

Example 2 with PrefixGlobalUpdateRequest

use of net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest in project FunnyGuilds by FunnyGuilds.

the class Flat method loadGuilds.

private void loadGuilds() {
    GuildUtils.getGuilds().clear();
    File[] path = GUILDS.listFiles();
    if (path != null) {
        for (File file : path) {
            Guild guild = FlatGuild.deserialize(file);
            if (guild == null) {
                file.delete();
            } else {
                guild.changed();
            }
        }
    }
    // TODO
    for (Guild guild : GuildUtils.getGuilds()) {
        if (guild.getOwner() != null) {
            continue;
        }
        GuildUtils.deleteGuild(guild);
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalUpdateRequest());
    FunnyLogger.info("Loaded guilds: " + GuildUtils.getGuilds().size());
}
Also used : ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Guild(net.dzikoysk.funnyguilds.basic.Guild) File(java.io.File) PrefixGlobalUpdateRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)2 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)2 PrefixGlobalUpdateRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)2 File (java.io.File)1 SQLException (java.sql.SQLException)1 Region (net.dzikoysk.funnyguilds.basic.Region)1 User (net.dzikoysk.funnyguilds.basic.User)1 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)1