mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-06 03:38:06 +02:00
WorldAliasSettings initialized by Dagger, ConnectionLog changes
This commit is contained in:
parent
ed40c916fb
commit
ff02eefb20
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.connection;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.request.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
@ -14,6 +15,7 @@ import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -28,7 +30,6 @@ import java.util.UUID;
|
||||
public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
|
||||
private final Database database;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebServer webServer;
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@ -37,14 +38,15 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
@Inject
|
||||
public BungeeConnectionSystem(
|
||||
Database database,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
ConnectionLog connectionLog,
|
||||
InfoRequests infoRequests,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(infoRequests);
|
||||
super(connectionLog, infoRequests, infoSystem, serverInfo);
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
|
@ -7,7 +7,6 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.info.request.SetupRequest;
|
||||
import com.djrapitops.plan.system.webserver.Request;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -23,8 +22,16 @@ public class ConnectionIn {
|
||||
|
||||
private final Map<String, String> variables;
|
||||
private final InfoRequest infoRequest;
|
||||
private final Database database;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
public ConnectionIn(Request httpRequest, InfoRequest infoRequest) throws WebException {
|
||||
public ConnectionIn(
|
||||
Request httpRequest, InfoRequest infoRequest,
|
||||
Database database,
|
||||
ConnectionSystem connectionSystem
|
||||
) throws WebException {
|
||||
this.database = database;
|
||||
this.connectionSystem = connectionSystem;
|
||||
Verify.nullCheck(httpRequest, infoRequest);
|
||||
|
||||
this.variables = readVariables(httpRequest);
|
||||
@ -37,17 +44,15 @@ public class ConnectionIn {
|
||||
UUID serverUUID = getServerUUID();
|
||||
|
||||
try {
|
||||
if (Database.getActive().check().isServerInDatabase(serverUUID)) {
|
||||
if (database.check().isServerInDatabase(serverUUID)) {
|
||||
return;
|
||||
}
|
||||
} catch (DBOpException e) {
|
||||
throw new TransferDatabaseException(e);
|
||||
}
|
||||
|
||||
Log.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName());
|
||||
|
||||
if (infoRequest instanceof SetupRequest) {
|
||||
if (!ConnectionSystem.isSetupAllowed_Old()) {
|
||||
if (!connectionSystem.isSetupAllowed()) {
|
||||
throw new ForbiddenException("Setup not enabled on this server, use commands to enable.");
|
||||
}
|
||||
} else {
|
||||
|
@ -7,23 +7,28 @@ package com.djrapitops.plan.system.info.connection;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Class responsible for logging what ConnectionOut objects get in return.
|
||||
* Class responsible for logging what {@link ConnectionOut} and {@link ConnectionIn} objects get as response.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ConnectionLog {
|
||||
|
||||
private Map<String, Map<String, Entry>> log;
|
||||
private final DebugLogger debugLogger;
|
||||
|
||||
public ConnectionLog() {
|
||||
this.log = new HashMap<>();
|
||||
private final Map<String, Map<String, Entry>> log;
|
||||
|
||||
@Inject
|
||||
public ConnectionLog(DebugLogger debugLogger) {
|
||||
this.debugLogger = debugLogger;
|
||||
log = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,34 +36,45 @@ public class ConnectionLog {
|
||||
*
|
||||
* @return {@code Map<"In: "/"Out: "+Address, Map<InfoRequestClassname, ConnectionLog.Entry>>}
|
||||
*/
|
||||
public static Map<String, Map<String, Entry>> getLogEntries() {
|
||||
return getInstance().getLog();
|
||||
@Deprecated
|
||||
public static Map<String, Map<String, Entry>> getLogEntries_Old() {
|
||||
return getInstance().getLogEntries();
|
||||
}
|
||||
|
||||
public static void logConnectionTo(Server server, InfoRequest request, int responseCode) {
|
||||
@Deprecated
|
||||
public static void logConnectionTo_Old(Server server, InfoRequest request, int responseCode) {
|
||||
getInstance().logConnectionTo(server, request, responseCode);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void logConnectionFrom_Old(String server, String requestTarget, int responseCode) {
|
||||
getInstance().logConnectionFrom(server, requestTarget, responseCode);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static ConnectionLog getInstance() {
|
||||
return ConnectionSystem.getInstance().getConnectionLog();
|
||||
}
|
||||
|
||||
public void logConnectionTo(Server server, InfoRequest request, int responseCode) {
|
||||
String requestName = request.getClass().getSimpleName();
|
||||
String address = server.getWebAddress();
|
||||
logConnection(address, "Out: " + requestName, responseCode);
|
||||
Log.debug("ConnectionOut: " + requestName + " to " + address);
|
||||
debugLogger.logOn("Connections", "ConnectionOut: " + requestName + " to " + address);
|
||||
}
|
||||
|
||||
public static void logConnectionFrom(String server, String requestTarget, int responseCode) {
|
||||
public void logConnectionFrom(String server, String requestTarget, int responseCode) {
|
||||
logConnection(server, "In: " + requestTarget, responseCode);
|
||||
Log.debug("ConnectionIn: " + requestTarget + " from " + server);
|
||||
debugLogger.logOn("Connections", "ConnectionIn: " + requestTarget + " from " + server);
|
||||
}
|
||||
|
||||
private static void logConnection(String address, String infoRequestName, int responseCode) {
|
||||
Map<String, Map<String, Entry>> log = getInstance().log;
|
||||
private void logConnection(String address, String infoRequestName, int responseCode) {
|
||||
Map<String, Entry> requestMap = log.getOrDefault(address, new HashMap<>());
|
||||
requestMap.put(infoRequestName, new Entry(responseCode, System.currentTimeMillis()));
|
||||
log.put(address, requestMap);
|
||||
}
|
||||
|
||||
private static ConnectionLog getInstance() {
|
||||
return ConnectionSystem.getInstance().getConnectionLog();
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Entry>> getLog() {
|
||||
public Map<String, Map<String, Entry>> getLogEntries() {
|
||||
return log;
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,8 @@ import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequestWithVariables;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
@ -57,14 +55,20 @@ public class ConnectionOut {
|
||||
}
|
||||
}
|
||||
|
||||
private final ConnectionLog connectionLog;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param toServer Full address to another Plan webserver. (http://something:port)
|
||||
* @param toServer Full address to another Plan webserver. (http://something:port)
|
||||
* @param serverUUID UUID of server this outbound connection.
|
||||
* @param infoRequest Type of the action this connection wants to be performed.
|
||||
* @param connectionLog
|
||||
*/
|
||||
public ConnectionOut(Server toServer, UUID serverUUID, InfoRequest infoRequest) {
|
||||
public ConnectionOut(
|
||||
Server toServer, UUID serverUUID, InfoRequest infoRequest,
|
||||
ConnectionLog connectionLog
|
||||
) {
|
||||
this.connectionLog = connectionLog;
|
||||
Verify.nullCheck(toServer, serverUUID, infoRequest);
|
||||
this.toServer = toServer;
|
||||
this.serverUUID = serverUUID;
|
||||
@ -91,14 +95,10 @@ public class ConnectionOut {
|
||||
|
||||
handleResult(url, parameters, responseCode);
|
||||
} catch (SocketTimeoutException e) {
|
||||
ConnectionLog.logConnectionTo(toServer, infoRequest, 0);
|
||||
connectionLog.logConnectionTo(toServer, infoRequest, 0);
|
||||
throw new ConnectionFailException("Connection to " + address + " timed out after 10 seconds.", e);
|
||||
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException | IOException e) {
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
Log.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:");
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
ConnectionLog.logConnectionTo(toServer, infoRequest, -1);
|
||||
connectionLog.logConnectionTo(toServer, infoRequest, -1);
|
||||
throw new ConnectionFailException("Connection failed to address: " + address + " - Make sure the server is online.", e);
|
||||
} finally {
|
||||
if (post != null) {
|
||||
@ -110,7 +110,7 @@ public class ConnectionOut {
|
||||
}
|
||||
|
||||
private void handleResult(String url, String parameters, int responseCode) throws WebException {
|
||||
ConnectionLog.logConnectionTo(toServer, infoRequest, responseCode);
|
||||
connectionLog.logConnectionTo(toServer, infoRequest, responseCode);
|
||||
switch (responseCode) {
|
||||
case 200:
|
||||
return;
|
||||
|
@ -13,6 +13,7 @@ import com.djrapitops.plan.system.info.request.WideRequest;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import dagger.Lazy;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -27,14 +28,24 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
|
||||
protected final ConnectionLog connectionLog;
|
||||
protected final Map<String, InfoRequest> dataRequests;
|
||||
protected final Lazy<InfoSystem> infoSystem;
|
||||
protected final ServerInfo serverInfo;
|
||||
|
||||
protected Map<UUID, Server> bukkitServers;
|
||||
private boolean setupAllowed;
|
||||
|
||||
public ConnectionSystem(Map<String, InfoRequest> dataRequests) {
|
||||
public ConnectionSystem(
|
||||
ConnectionLog connectionLog,
|
||||
Map<String, InfoRequest> dataRequests,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
this.connectionLog = connectionLog;
|
||||
this.infoSystem = infoSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
setupAllowed = false;
|
||||
bukkitServers = new HashMap<>();
|
||||
this.dataRequests = dataRequests;
|
||||
connectionLog = new ConnectionLog();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -44,16 +55,6 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
return connectionSystem;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isSetupAllowed_Old() {
|
||||
return getInstance().setupAllowed;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getAddress() {
|
||||
return getInstance().getMainAddress();
|
||||
}
|
||||
|
||||
public InfoRequest getInfoRequest(String name) {
|
||||
return dataRequests.get(name.toLowerCase());
|
||||
}
|
||||
@ -62,10 +63,6 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
this.setupAllowed = setupAllowed;
|
||||
}
|
||||
|
||||
private void putRequest(InfoRequest request) {
|
||||
dataRequests.put(request.getClass().getSimpleName().toLowerCase(), request);
|
||||
}
|
||||
|
||||
protected abstract Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException;
|
||||
|
||||
public boolean isSetupAllowed() {
|
||||
@ -78,10 +75,11 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
}
|
||||
|
||||
public void sendInfoRequest(InfoRequest infoRequest, Server toServer) throws WebException {
|
||||
if (ServerInfo.getServerUUID_Old().equals(toServer.getUuid())) {
|
||||
InfoSystem.getInstance().runLocally(infoRequest);
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
if (serverUUID.equals(toServer.getUuid())) {
|
||||
infoSystem.get().runLocally(infoRequest);
|
||||
} else {
|
||||
new ConnectionOut(toServer, ServerInfo.getServerUUID_Old(), infoRequest).sendRequest();
|
||||
new ConnectionOut(toServer, serverUUID, infoRequest, connectionLog).sendRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
||||
import com.djrapitops.plan.system.webserver.Request;
|
||||
@ -13,6 +14,7 @@ import com.djrapitops.plan.system.webserver.pages.PageHandler;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -31,11 +33,19 @@ import java.util.List;
|
||||
@Singleton
|
||||
public class InfoRequestPageHandler implements PageHandler {
|
||||
|
||||
private final Database database;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final PluginLogger logger;
|
||||
|
||||
@Inject
|
||||
public InfoRequestPageHandler(ConnectionSystem connectionSystem) {
|
||||
public InfoRequestPageHandler(
|
||||
Database database,
|
||||
ConnectionSystem connectionSystem,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.database = database;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,12 +66,13 @@ public class InfoRequestPageHandler implements PageHandler {
|
||||
|
||||
Verify.nullCheck(infoRequest, () -> new NotFoundException("Info Request has not been registered."));
|
||||
|
||||
return new ConnectionIn(request, infoRequest).handleRequest();
|
||||
logger.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName());
|
||||
return new ConnectionIn(request, infoRequest, database, connectionSystem).handleRequest();
|
||||
} catch (WebException e) {
|
||||
responseCode = getResponseCodeFor(e);
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionLog.logConnectionFrom(request.getRemoteAddress(), request.getTarget(), responseCode);
|
||||
ConnectionLog.logConnectionFrom_Old(request.getRemoteAddress(), request.getTarget(), responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.connection;
|
||||
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.request.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
@ -19,6 +20,7 @@ import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -37,7 +39,6 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
private final PlanConfig config;
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private final ServerInfo serverInfo;
|
||||
private final PluginLogger pluginLogger;
|
||||
|
||||
private long latestServerMapRefresh;
|
||||
@ -50,16 +51,17 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
PlanConfig config,
|
||||
Database database,
|
||||
WebServer webServer,
|
||||
ServerInfo serverInfo,
|
||||
ConnectionLog connectionLog,
|
||||
InfoRequests infoRequests,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
PluginLogger pluginLogger
|
||||
) {
|
||||
super(infoRequests);
|
||||
super(connectionLog, infoRequests, infoSystem, serverInfo);
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.database = database;
|
||||
this.webServer = webServer;
|
||||
this.serverInfo = serverInfo;
|
||||
this.pluginLogger = pluginLogger;
|
||||
latestServerMapRefresh = 0;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class WebExceptionLogger {
|
||||
|
||||
@Deprecated
|
||||
public static void logIfOccurs(Class c, ThrowingVoidFunction<WebException> function) {
|
||||
try {
|
||||
function.apply();
|
||||
@ -35,12 +36,13 @@ public class WebExceptionLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static boolean shouldLog(ConnectionFailException e) {
|
||||
String address = getAddress(e);
|
||||
if (address == null) {
|
||||
return true;
|
||||
}
|
||||
Map<String, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries();
|
||||
Map<String, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries_Old();
|
||||
Map<String, ConnectionLog.Entry> entries = logEntries.get("Out: " + address);
|
||||
if (entries != null) {
|
||||
List<ConnectionLog.Entry> connections = new ArrayList<>(entries.values());
|
||||
|
@ -8,6 +8,7 @@ import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -26,22 +27,24 @@ import java.util.UUID;
|
||||
@Singleton
|
||||
public class ServerSpecificSettings {
|
||||
|
||||
private final Lazy<PlanConfig> config;
|
||||
|
||||
private final PluginLogger logger;
|
||||
private PlanConfig config;
|
||||
|
||||
@Inject
|
||||
public ServerSpecificSettings(PluginLogger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void setConfig(PlanConfig config) {
|
||||
public ServerSpecificSettings(
|
||||
Lazy<PlanConfig> config,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.config = config;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void updateSettings(Map<String, String> settings) throws IOException {
|
||||
logger.debug("Checking new settings..");
|
||||
|
||||
boolean changedSomething = false;
|
||||
PlanConfig planConfig = config.get();
|
||||
for (Map.Entry<String, String> setting : settings.entrySet()) {
|
||||
try {
|
||||
String path = setting.getKey();
|
||||
@ -50,11 +53,11 @@ public class ServerSpecificSettings {
|
||||
}
|
||||
String stringValue = setting.getValue();
|
||||
Object value = getValue(stringValue);
|
||||
String currentValue = config.getString(path);
|
||||
String currentValue = planConfig.getString(path);
|
||||
if (stringValue.equals(currentValue)) {
|
||||
continue;
|
||||
}
|
||||
config.set(path, value);
|
||||
planConfig.set(path, value);
|
||||
logger.debug(" " + path + ": " + value);
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
@ -62,7 +65,7 @@ public class ServerSpecificSettings {
|
||||
}
|
||||
|
||||
if (changedSomething) {
|
||||
config.save();
|
||||
planConfig.save();
|
||||
logger.info("----------------------------------");
|
||||
logger.info("The Received Bungee Settings changed the config values, restarting Plan..");
|
||||
logger.info("----------------------------------");
|
||||
@ -87,13 +90,14 @@ public class ServerSpecificSettings {
|
||||
}
|
||||
|
||||
public void addOriginalBukkitSettings(UUID serverUUID, Map<String, Object> settings) throws IOException {
|
||||
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
|
||||
PlanConfig planConfig = config.get();
|
||||
if (!Verify.isEmpty(planConfig.getString("Servers." + serverUUID + ".ServerName"))) {
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : settings.entrySet()) {
|
||||
config.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
|
||||
planConfig.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
|
||||
}
|
||||
config.save();
|
||||
planConfig.save();
|
||||
}
|
||||
|
||||
private String getPath(UUID serverUUID, Settings setting) {
|
||||
@ -116,22 +120,23 @@ public class ServerSpecificSettings {
|
||||
|
||||
public boolean getBoolean(UUID serverUUID, Settings setting) {
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getBoolean(path);
|
||||
return config.get().getBoolean(path);
|
||||
}
|
||||
|
||||
public String getString(UUID serverUUID, Settings setting) {
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getString(path);
|
||||
return config.get().getString(path);
|
||||
}
|
||||
|
||||
public Integer getInt(UUID serverUUID, Settings setting) {
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getInt(path);
|
||||
return config.get().getInt(path);
|
||||
}
|
||||
|
||||
public void set(UUID serverUUID, Settings setting, Object value) throws IOException {
|
||||
String path = getPath(serverUUID, setting);
|
||||
config.set(path, value);
|
||||
config.save();
|
||||
PlanConfig planConfig = config.get();
|
||||
planConfig.set(path, value);
|
||||
planConfig.save();
|
||||
}
|
||||
}
|
||||
|
@ -5,30 +5,56 @@
|
||||
package com.djrapitops.plan.system.settings;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.config.Config;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.config.ConfigNode;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class responsible for managing Bukkit side config settings for World Aliases.
|
||||
* Class responsible for managing config settings for World Aliases.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class WorldAliasSettings {
|
||||
|
||||
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public WorldAliasSettings(Lazy<PlanConfig> config, ErrorHandler errorHandler) {
|
||||
this.config = config;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Map<String, String> getAliases_Old() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addWorld_Old(String world) {
|
||||
|
||||
}
|
||||
|
||||
private ConfigNode getAliasSection() {
|
||||
return config.get().getConfigNode(Settings.WORLD_ALIASES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get all World aliases in the config
|
||||
*
|
||||
* @return Map: Original name, Alias
|
||||
*/
|
||||
@Deprecated
|
||||
public static Map<String, String> getAliases_Old() {
|
||||
public Map<String, String> getAliases() {
|
||||
ConfigNode aliasSect = getAliasSection();
|
||||
|
||||
Map<String, String> aliasMap = new HashMap<>();
|
||||
@ -38,11 +64,6 @@ public class WorldAliasSettings {
|
||||
return aliasMap;
|
||||
}
|
||||
|
||||
private static ConfigNode getAliasSection() {
|
||||
Config config = ConfigSystem.getConfig_Old();
|
||||
return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new World to the config section.
|
||||
* <p>
|
||||
@ -50,8 +71,7 @@ public class WorldAliasSettings {
|
||||
*
|
||||
* @param world World name
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addWorld_Old(String world) {
|
||||
public void addWorld(String world) {
|
||||
ConfigNode aliasSect = getAliasSection();
|
||||
|
||||
String previousValue = aliasSect.getConfigNode(world).getValue();
|
||||
@ -61,7 +81,7 @@ public class WorldAliasSettings {
|
||||
try {
|
||||
aliasSect.save();
|
||||
} catch (IOException e) {
|
||||
Log.toLog(WorldAliasSettings.class, e);
|
||||
errorHandler.log(L.WARN, WorldAliasSettings.class, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.djrapitops.plan.system.settings.config;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.system.settings.network.NetworkSettings;
|
||||
import com.djrapitops.plugin.config.Config;
|
||||
import com.djrapitops.plugin.config.ConfigNode;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@ -14,20 +17,23 @@ import java.util.List;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class PlanConfig extends Config {
|
||||
|
||||
private final PluginsConfigSection pluginsConfigSection;
|
||||
private final NetworkSettings networkSettings;
|
||||
private final WorldAliasSettings worldAliasSettings;
|
||||
|
||||
@Inject
|
||||
public PlanConfig(
|
||||
@Named("configFile") File file,
|
||||
NetworkSettings networkSettings
|
||||
NetworkSettings networkSettings,
|
||||
WorldAliasSettings worldAliasSettings
|
||||
) {
|
||||
super(file);
|
||||
|
||||
this.networkSettings = networkSettings;
|
||||
networkSettings.setConfig(this);
|
||||
this.worldAliasSettings = worldAliasSettings;
|
||||
|
||||
pluginsConfigSection = new PluginsConfigSection(this);
|
||||
}
|
||||
@ -62,6 +68,10 @@ public class PlanConfig extends Config {
|
||||
return getStringList(setting.getPath());
|
||||
}
|
||||
|
||||
public ConfigNode getConfigNode(Setting setting) {
|
||||
return getConfigNode(setting.getPath());
|
||||
}
|
||||
|
||||
public void set(Setting setting, Object value) {
|
||||
set(setting.getPath(), value);
|
||||
}
|
||||
@ -73,4 +83,8 @@ public class PlanConfig extends Config {
|
||||
public NetworkSettings getNetworkSettings() {
|
||||
return networkSettings;
|
||||
}
|
||||
|
||||
public WorldAliasSettings getWorldAliasSettings() {
|
||||
return worldAliasSettings;
|
||||
}
|
||||
}
|
@ -39,21 +39,23 @@ public class NetworkSettings {
|
||||
private static final String SPLIT = ";;SETTING;;";
|
||||
private static final String VAL_SPLIT = ";;VALUE;;";
|
||||
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final Lazy<Database> database;
|
||||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final ServerSpecificSettings serverSpecificSettings;
|
||||
private PlanConfig config;
|
||||
|
||||
@Inject
|
||||
public NetworkSettings(
|
||||
Lazy<PlanConfig> config,
|
||||
ServerSpecificSettings serverSpecificSettings,
|
||||
Lazy<Database> database,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.serverSpecificSettings = serverSpecificSettings;
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -61,17 +63,13 @@ public class NetworkSettings {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public void setConfig(PlanConfig config) {
|
||||
this.config = config;
|
||||
serverSpecificSettings.setConfig(config);
|
||||
}
|
||||
|
||||
public void loadSettingsFromDB() {
|
||||
if (Check.isBungeeAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.isTrue(BUNGEE_OVERRIDE_STANDALONE_MODE) || config.isFalse(BUNGEE_COPY_CONFIG)) {
|
||||
PlanConfig planConfig = config.get();
|
||||
if (planConfig.isTrue(BUNGEE_OVERRIDE_STANDALONE_MODE) || planConfig.isFalse(BUNGEE_COPY_CONFIG)) {
|
||||
// Don't load settings if they are overridden.
|
||||
return;
|
||||
}
|
||||
@ -203,10 +201,11 @@ public class NetworkSettings {
|
||||
KEEP_INACTIVE_PLAYERS_DAYS
|
||||
};
|
||||
logger.debug("NetworkSettings: Adding Config Values..");
|
||||
PlanConfig planConfig = config.get();
|
||||
for (Settings setting : sameStrings) {
|
||||
addConfigValue(configValues, setting, config.getString(setting));
|
||||
addConfigValue(configValues, setting, planConfig.getString(setting));
|
||||
}
|
||||
addConfigValue(configValues, DB_PORT, config.getNumber(DB_PORT));
|
||||
addConfigValue(configValues, DB_PORT, planConfig.getNumber(DB_PORT));
|
||||
addServerSpecificValues(configValues);
|
||||
return configValues;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ public class DebugPage implements Page {
|
||||
|
||||
private void appendConnectionLog(StringBuilder content) {
|
||||
try {
|
||||
Map<String, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries();
|
||||
Map<String, Map<String, ConnectionLog.Entry>> logEntries = connectionSystem.getConnectionLog().getLogEntries();
|
||||
|
||||
content.append("<pre>### Connection Log:<br><br>");
|
||||
content.append("Server Address | Request Type | Response | Sent<br>")
|
||||
|
Loading…
Reference in New Issue
Block a user