Search in sources :

Example 1 with NewerConfigQuery

use of com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery in project Plan by plan-player-analytics.

the class NetworkSettingManager method updateConfigFromDBIfUpdated.

private void updateConfigFromDBIfUpdated(Database database, ServerUUID serverUUID) {
    File configFile = getServerConfigFile(serverUUID);
    long lastModified = configFile.exists() ? configFile.lastModified() : -1;
    Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverUUID, lastModified));
    if (foundConfig.isPresent()) {
        try {
            Config writing = foundConfig.get();
            String serverName = writing.getNode(PluginSettings.SERVER_NAME.getPath()).map(ConfigNode::getString).orElse("Unknown");
            new ConfigWriter(configFile.toPath()).write(writing);
            logger.info("Config file for server '" + serverName + "' updated in /Plan/serverConfiguration");
            addFileToWatchList(watcher, configFile);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}
Also used : NewerConfigQuery(com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) WatchedFile(com.djrapitops.plan.settings.upkeep.WatchedFile) File(java.io.File)

Example 2 with NewerConfigQuery

use of com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery in project Plan by plan-player-analytics.

the class ServerSettingsManager method checkDBForNewConfigSettings.

private void checkDBForNewConfigSettings(Database database) {
    File configFile = files.getConfigFile();
    long lastModified = configFile.exists() ? configFile.lastModified() : -1;
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverUUID.get(), lastModified));
    if (foundConfig.isPresent()) {
        try {
            new ConfigWriter(configFile.toPath()).write(foundConfig.get());
            logger.info("The Config was updated to match one on the Proxy. Reload for changes to take effect.");
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}
Also used : ConfigWriter(com.djrapitops.plan.settings.config.ConfigWriter) NewerConfigQuery(com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) WatchedFile(com.djrapitops.plan.settings.upkeep.WatchedFile) File(java.io.File)

Aggregations

WatchedFile (com.djrapitops.plan.settings.upkeep.WatchedFile)2 NewerConfigQuery (com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery)2 File (java.io.File)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 Config (com.djrapitops.plan.settings.config.Config)1 ConfigWriter (com.djrapitops.plan.settings.config.ConfigWriter)1 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)1