mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-20 01:25:37 +01:00
Removed original settings sending on /plan m setup
This commit is contained in:
parent
00a28e283b
commit
858f197e58
@ -127,7 +127,7 @@ public class InfoRequestFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SetupRequest sendDBSettingsRequest(String addressOfThisServer) {
|
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) {
|
public CheckConnectionRequest checkConnectionRequest(String webAddress) {
|
||||||
@ -213,7 +213,6 @@ public class InfoRequestFactory {
|
|||||||
|
|
||||||
SetupRequest sendDBSettingsRequest() {
|
SetupRequest sendDBSettingsRequest() {
|
||||||
return new SendDBSettingsRequest(
|
return new SendDBSettingsRequest(
|
||||||
factory.config.get(),
|
|
||||||
factory,
|
factory,
|
||||||
factory.connectionSystem.get()
|
factory.connectionSystem.get()
|
||||||
);
|
);
|
||||||
|
@ -61,11 +61,11 @@ public class SaveDBSettingsRequest extends InfoRequestWithVariables implements S
|
|||||||
this.runnableFactory = runnableFactory;
|
this.runnableFactory = runnableFactory;
|
||||||
|
|
||||||
variables.put("DB_TYPE", "mysql"); // DatabaseSettings.TYPE
|
variables.put("DB_TYPE", "mysql"); // DatabaseSettings.TYPE
|
||||||
variables.put("DB_HOST", config.getString(DatabaseSettings.MYSQL_HOST));
|
variables.put("DB_HOST", config.get(DatabaseSettings.MYSQL_HOST));
|
||||||
variables.put("DB_USER", config.getString(DatabaseSettings.MYSQL_USER));
|
variables.put("DB_USER", config.get(DatabaseSettings.MYSQL_USER));
|
||||||
variables.put("DB_PASS", config.getString(DatabaseSettings.MYSQL_PASS));
|
variables.put("DB_PASS", config.get(DatabaseSettings.MYSQL_PASS));
|
||||||
variables.put("DB_DATABASE", config.getString(DatabaseSettings.MYSQL_DATABASE));
|
variables.put("DB_DATABASE", config.get(DatabaseSettings.MYSQL_DATABASE));
|
||||||
variables.put("DB_PORT", config.getString(DatabaseSettings.MYSQL_PORT));
|
variables.put("DB_PORT", config.get(DatabaseSettings.MYSQL_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(database, () -> new BadRequestException("DB_DATABASE not specified in the request."));
|
||||||
Verify.nullCheck(portS, () -> new BadRequestException("DB_PORT not specified in the request."));
|
Verify.nullCheck(portS, () -> new BadRequestException("DB_PORT not specified in the request."));
|
||||||
|
|
||||||
try {
|
|
||||||
config.set(DatabaseSettings.MYSQL_PORT, portS);
|
config.set(DatabaseSettings.MYSQL_PORT, portS);
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new BadRequestException("DB_PORT was not a number.");
|
|
||||||
}
|
|
||||||
config.set(DatabaseSettings.TYPE, type);
|
config.set(DatabaseSettings.TYPE, type);
|
||||||
config.set(DatabaseSettings.MYSQL_HOST, host);
|
config.set(DatabaseSettings.MYSQL_HOST, host);
|
||||||
config.set(DatabaseSettings.MYSQL_USER, user);
|
config.set(DatabaseSettings.MYSQL_USER, user);
|
||||||
|
@ -16,22 +16,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.info.request;
|
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.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
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.DefaultResponses;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
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.BadRequestResponse;
|
||||||
import com.djrapitops.plugin.api.Check;
|
import com.djrapitops.plugin.api.Check;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -42,33 +39,25 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class SendDBSettingsRequest extends InfoRequestWithVariables implements SetupRequest {
|
public class SendDBSettingsRequest extends InfoRequestWithVariables implements SetupRequest {
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final InfoRequestFactory infoRequestFactory;
|
private final InfoRequestFactory infoRequestFactory;
|
||||||
private final ConnectionSystem connectionSystem;
|
private final ConnectionSystem connectionSystem;
|
||||||
|
|
||||||
SendDBSettingsRequest(
|
SendDBSettingsRequest(
|
||||||
PlanConfig config,
|
|
||||||
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
|
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
|
||||||
) {
|
) {
|
||||||
this.config = config;
|
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
this.connectionSystem = connectionSystem;
|
this.connectionSystem = connectionSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendDBSettingsRequest(
|
SendDBSettingsRequest(
|
||||||
String webServerAddress,
|
String webServerAddress,
|
||||||
PlanConfig config,
|
|
||||||
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
|
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
|
||||||
) {
|
) {
|
||||||
this.config = config;
|
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
this.connectionSystem = connectionSystem;
|
this.connectionSystem = connectionSystem;
|
||||||
|
|
||||||
Verify.nullCheck(webServerAddress, () -> new IllegalArgumentException("webServerAddress can not be null."));
|
Verify.nullCheck(webServerAddress, () -> new IllegalArgumentException("webServerAddress can not be null."));
|
||||||
variables.put("address", webServerAddress);
|
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
|
@Override
|
||||||
@ -89,17 +78,9 @@ public class SendDBSettingsRequest extends InfoRequestWithVariables implements S
|
|||||||
String address = variables.get("address");
|
String address = variables.get("address");
|
||||||
Verify.nullCheck(address, () -> new BadRequestException("WebServer Address ('address') not specified in the request."));
|
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"));
|
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 {
|
try {
|
||||||
connectionSystem.sendInfoRequest(infoRequestFactory.saveDBSettingsRequest(), bukkit);
|
connectionSystem.sendInfoRequest(infoRequestFactory.saveDBSettingsRequest(), bukkit);
|
||||||
@ -112,18 +93,4 @@ public class SendDBSettingsRequest extends InfoRequestWithVariables implements S
|
|||||||
|
|
||||||
return DefaultResponses.SUCCESS.get();
|
return DefaultResponses.SUCCESS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOriginalSettings(UUID serverUUID, String webServerPortS, String serverName, String themeBase) throws InternalErrorException {
|
|
||||||
Map<String, Object> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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.WebserverSettings;
|
||||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
import dagger.Lazy;
|
import dagger.Lazy;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -109,17 +108,6 @@ public class ServerSpecificSettings {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOriginalBukkitSettings(UUID serverUUID, Map<String, Object> settings) throws IOException {
|
|
||||||
PlanConfig planConfig = config.get();
|
|
||||||
if (!Verify.isEmpty(planConfig.getString("Servers." + serverUUID + ".ServerName"))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Object> entry : settings.entrySet()) {
|
|
||||||
planConfig.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
planConfig.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPath(UUID serverUUID, Setting setting) {
|
private String getPath(UUID serverUUID, Setting setting) {
|
||||||
String path = "Servers." + serverUUID;
|
String path = "Servers." + serverUUID;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user