Search in sources :

Example 1 with Config

use of com.djrapitops.plan.settings.config.Config in project Plan by plan-player-analytics.

the class ServerSettingsManager method updateConfigInDB.

private void updateConfigInDB(File file) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config read = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) ConfigReader(com.djrapitops.plan.settings.config.ConfigReader) Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with Config

use of com.djrapitops.plan.settings.config.Config 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)

Example 3 with Config

use of com.djrapitops.plan.settings.config.Config in project Plan by plan-player-analytics.

the class DatabaseTest method configIsStoredInTheDatabase.

@Test
default void configIsStoredInTheDatabase() {
    PlanConfig config = config();
    db().executeTransaction(new StoreConfigTransaction(serverUUID(), config, System.currentTimeMillis()));
    Optional<Config> foundConfig = db().query(new NewerConfigQuery(serverUUID(), 0));
    assertTrue(foundConfig.isPresent());
    assertEquals(config, foundConfig.get());
}
Also used : PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Config (com.djrapitops.plan.settings.config.Config)3 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 StoreConfigTransaction (com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ConfigReader (com.djrapitops.plan.settings.config.ConfigReader)1 ConfigWriter (com.djrapitops.plan.settings.config.ConfigWriter)1 WatchedFile (com.djrapitops.plan.settings.upkeep.WatchedFile)1 Database (com.djrapitops.plan.storage.database.Database)1 NewerConfigQuery (com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1