mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-20 07:02:21 +01:00
Fixed exception on boot if settings changed
This commit is contained in:
parent
9df819b27a
commit
813eaf4c81
@ -21,6 +21,7 @@ import com.djrapitops.plan.exceptions.EnableException;
|
|||||||
import com.djrapitops.plan.identification.properties.ServerProperties;
|
import com.djrapitops.plan.identification.properties.ServerProperties;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,6 +48,10 @@ public abstract class ServerInfo implements SubSystem {
|
|||||||
return getServer().getUuid();
|
return getServer().getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<UUID> getServerUUIDSafe() {
|
||||||
|
return Optional.ofNullable(server).map(Server::getUuid);
|
||||||
|
}
|
||||||
|
|
||||||
public ServerProperties getServerProperties() {
|
public ServerProperties getServerProperties() {
|
||||||
return serverProperties;
|
return serverProperties;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package com.djrapitops.plan.query;
|
package com.djrapitops.plan.query;
|
||||||
|
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.identification.Server;
|
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
import com.djrapitops.plan.storage.database.Database;
|
||||||
@ -127,7 +126,7 @@ public class QueryServiceImplementation implements QueryService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UUID> getServerUUID() {
|
public Optional<UUID> getServerUUID() {
|
||||||
return Optional.ofNullable(serverInfo.getServer()).map(Server::getUuid);
|
return serverInfo.getServerUUIDSafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,6 +42,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,10 +109,14 @@ public class ServerSettingsManager implements SubSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
|
Optional<UUID> serverUUID = serverInfo.getServerUUIDSafe();
|
||||||
|
if (!serverUUID.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
||||||
Config read = reader.read();
|
Config read = reader.read();
|
||||||
database.executeTransaction(new StoreConfigTransaction(serverInfo.getServerUUID(), read, file.lastModified()));
|
database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
|
||||||
logger.debug("Server config saved to database.");
|
logger.debug("Server config saved to database.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
@ -132,7 +137,12 @@ public class ServerSettingsManager implements SubSystem {
|
|||||||
File configFile = files.getConfigFile();
|
File configFile = files.getConfigFile();
|
||||||
long lastModified = configFile.exists() ? configFile.lastModified() : -1;
|
long lastModified = configFile.exists() ? configFile.lastModified() : -1;
|
||||||
|
|
||||||
Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverInfo.getServerUUID(), lastModified));
|
Optional<UUID> serverUUID = serverInfo.getServerUUIDSafe();
|
||||||
|
if (!serverUUID.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverUUID.get(), lastModified));
|
||||||
if (foundConfig.isPresent()) {
|
if (foundConfig.isPresent()) {
|
||||||
try {
|
try {
|
||||||
new ConfigWriter(configFile.toPath()).write(foundConfig.get());
|
new ConfigWriter(configFile.toPath()).write(foundConfig.get());
|
||||||
|
Loading…
Reference in New Issue
Block a user