From 858f197e58747684ad38775771594ccd25913399 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 10 Dec 2018 19:49:15 +0200 Subject: [PATCH] Removed original settings sending on /plan m setup --- .../info/request/InfoRequestFactory.java | 3 +- .../info/request/SaveDBSettingsRequest.java | 16 +++---- .../info/request/SendDBSettingsRequest.java | 43 +++---------------- .../settings/ServerSpecificSettings.java | 12 ------ 4 files changed, 12 insertions(+), 62 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/InfoRequestFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/InfoRequestFactory.java index d5c5689e0..5d3635a4a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/InfoRequestFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/InfoRequestFactory.java @@ -127,7 +127,7 @@ public class InfoRequestFactory { } public SetupRequest sendDBSettingsRequest(String addressOfThisServer) { - return new SendDBSettingsRequest(addressOfThisServer, config.get(), this, connectionSystem.get()); + return new SendDBSettingsRequest(addressOfThisServer, this, connectionSystem.get()); } public CheckConnectionRequest checkConnectionRequest(String webAddress) { @@ -213,7 +213,6 @@ public class InfoRequestFactory { SetupRequest sendDBSettingsRequest() { return new SendDBSettingsRequest( - factory.config.get(), factory, factory.connectionSystem.get() ); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SaveDBSettingsRequest.java b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SaveDBSettingsRequest.java index 3510e237c..73c28af60 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SaveDBSettingsRequest.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SaveDBSettingsRequest.java @@ -61,11 +61,11 @@ public class SaveDBSettingsRequest extends InfoRequestWithVariables implements S this.runnableFactory = runnableFactory; variables.put("DB_TYPE", "mysql"); // DatabaseSettings.TYPE - variables.put("DB_HOST", config.getString(DatabaseSettings.MYSQL_HOST)); - variables.put("DB_USER", config.getString(DatabaseSettings.MYSQL_USER)); - variables.put("DB_PASS", config.getString(DatabaseSettings.MYSQL_PASS)); - variables.put("DB_DATABASE", config.getString(DatabaseSettings.MYSQL_DATABASE)); - variables.put("DB_PORT", config.getString(DatabaseSettings.MYSQL_PORT)); + variables.put("DB_HOST", config.get(DatabaseSettings.MYSQL_HOST)); + variables.put("DB_USER", config.get(DatabaseSettings.MYSQL_USER)); + variables.put("DB_PASS", config.get(DatabaseSettings.MYSQL_PASS)); + variables.put("DB_DATABASE", config.get(DatabaseSettings.MYSQL_DATABASE)); + variables.put("DB_PORT", config.get(DatabaseSettings.MYSQL_PORT)); } @Override @@ -116,11 +116,7 @@ public class SaveDBSettingsRequest extends InfoRequestWithVariables implements S Verify.nullCheck(database, () -> new BadRequestException("DB_DATABASE not specified in the request.")); Verify.nullCheck(portS, () -> new BadRequestException("DB_PORT not specified in the request.")); - try { - config.set(DatabaseSettings.MYSQL_PORT, portS); - } catch (NumberFormatException e) { - throw new BadRequestException("DB_PORT was not a number."); - } + config.set(DatabaseSettings.MYSQL_PORT, portS); config.set(DatabaseSettings.TYPE, type); config.set(DatabaseSettings.MYSQL_HOST, host); config.set(DatabaseSettings.MYSQL_USER, user); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SendDBSettingsRequest.java b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SendDBSettingsRequest.java index 03f43282d..168398621 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SendDBSettingsRequest.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/info/request/SendDBSettingsRequest.java @@ -16,22 +16,19 @@ */ package com.djrapitops.plan.system.info.request; -import com.djrapitops.plan.api.exceptions.connection.*; +import com.djrapitops.plan.api.exceptions.connection.BadRequestException; +import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; +import com.djrapitops.plan.api.exceptions.connection.GatewayException; +import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.Server; -import com.djrapitops.plan.system.settings.config.PlanConfig; -import com.djrapitops.plan.system.settings.paths.DisplaySettings; -import com.djrapitops.plan.system.settings.paths.PluginSettings; -import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.webserver.response.DefaultResponses; import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse; import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.utilities.Verify; -import java.io.IOException; import java.net.SocketException; -import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -42,33 +39,25 @@ import java.util.UUID; */ public class SendDBSettingsRequest extends InfoRequestWithVariables implements SetupRequest { - private final PlanConfig config; private final InfoRequestFactory infoRequestFactory; private final ConnectionSystem connectionSystem; SendDBSettingsRequest( - PlanConfig config, InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem ) { - this.config = config; this.infoRequestFactory = infoRequestFactory; this.connectionSystem = connectionSystem; } SendDBSettingsRequest( String webServerAddress, - PlanConfig config, InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem ) { - this.config = config; this.infoRequestFactory = infoRequestFactory; this.connectionSystem = connectionSystem; Verify.nullCheck(webServerAddress, () -> new IllegalArgumentException("webServerAddress can not be null.")); variables.put("address", webServerAddress); - variables.put("WebServerPort", config.get(WebserverSettings.PORT).toString()); - variables.put("ServerName", config.get(PluginSettings.SERVER_NAME).replaceAll("[^a-zA-Z0-9_\\s]", "_")); - variables.put("ThemeBase", config.get(DisplaySettings.THEME)); } @Override @@ -89,17 +78,9 @@ public class SendDBSettingsRequest extends InfoRequestWithVariables implements S String address = variables.get("address"); Verify.nullCheck(address, () -> new BadRequestException("WebServer Address ('address') not specified in the request.")); - String webServerPortS = variables.get("WebServerPort"); - String serverName = variables.get("ServerName"); - String themeBase = variables.get("ThemeBase"); - Verify.nullCheck(webServerPortS, () -> new BadRequestException("WebServer Port ('WebServerPort') not specified in the request.")); - Verify.nullCheck(serverName, () -> new BadRequestException("Server Name ('ServerName') not specified in the request.")); - Verify.nullCheck(themeBase, () -> new BadRequestException("Theme Base ('ThemeBase') not specified in the request.")); - UUID serverUUID = UUID.fromString(variables.get("sender")); - setOriginalSettings(serverUUID, webServerPortS, serverName, themeBase); - Server bukkit = new Server(-1, serverUUID, serverName, address, -1); + Server bukkit = new Server(-1, serverUUID, null, address, -1); try { connectionSystem.sendInfoRequest(infoRequestFactory.saveDBSettingsRequest(), bukkit); @@ -112,18 +93,4 @@ public class SendDBSettingsRequest extends InfoRequestWithVariables implements S return DefaultResponses.SUCCESS.get(); } - - private void setOriginalSettings(UUID serverUUID, String webServerPortS, String serverName, String themeBase) throws InternalErrorException { - Map settings = new HashMap<>(); - int webServerPort = Integer.parseInt(webServerPortS); - settings.put("WebServerPort", webServerPort); - settings.put("ServerName", serverName); - settings.put("ThemeBase", themeBase); - - try { - config.getNetworkSettings().getServerSpecificSettings().addOriginalBukkitSettings(serverUUID, settings); - } catch (IOException e) { - throw new InternalErrorException("Failed to add Bukkit settings to config", e); - } - } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java index 5b9f14240..41936bf96 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java @@ -23,7 +23,6 @@ import com.djrapitops.plan.system.settings.paths.PluginSettings; import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.settings.paths.key.Setting; import com.djrapitops.plugin.logging.console.PluginLogger; -import com.djrapitops.plugin.utilities.Verify; import dagger.Lazy; import javax.inject.Inject; @@ -109,17 +108,6 @@ public class ServerSpecificSettings { return value; } - public void addOriginalBukkitSettings(UUID serverUUID, Map settings) throws IOException { - PlanConfig planConfig = config.get(); - if (!Verify.isEmpty(planConfig.getString("Servers." + serverUUID + ".ServerName"))) { - return; - } - for (Map.Entry entry : settings.entrySet()) { - planConfig.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue()); - } - planConfig.save(); - } - private String getPath(UUID serverUUID, Setting setting) { String path = "Servers." + serverUUID;