Removed NetworkSettings and ServerSpecificSettings

This commit is contained in:
Rsl1122 2018-12-24 12:01:41 +02:00
parent 5c6442fdb2
commit c68c95a608
7 changed files with 4 additions and 305 deletions

View File

@ -23,7 +23,6 @@ import com.djrapitops.plan.system.tasks.bungee.BungeeTPSCountTimer;
import com.djrapitops.plan.system.tasks.bungee.PingCountTimerBungee;
import com.djrapitops.plan.system.tasks.proxy.NetworkPageRefreshTask;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import javax.inject.Inject;
@ -72,12 +71,6 @@ public class BungeeTaskSystem extends TaskSystem {
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.toTicks(1L, TimeUnit.SECONDS));
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.toTicks(5L, TimeUnit.MINUTES));
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
registerTask("Settings Save", new AbsRunnable() {
@Override
public void run() {
config.getNetworkSettings().placeSettingsToDB();
}
}).runTaskAsynchronously();
plugin.registerListener(pingCountTimer);
long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS);

View File

@ -17,7 +17,6 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
import com.djrapitops.plan.system.settings.network.NetworkSettings;
import com.djrapitops.plan.system.settings.paths.TimeSettings;
import com.djrapitops.plan.system.settings.paths.key.Setting;
import com.djrapitops.plugin.utilities.Verify;
@ -39,18 +38,15 @@ import java.util.concurrent.TimeUnit;
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,
WorldAliasSettings worldAliasSettings
) {
super(file);
this.networkSettings = networkSettings;
this.worldAliasSettings = worldAliasSettings;
pluginsConfigSection = new PluginsConfigSection(this);
@ -115,10 +111,6 @@ public class PlanConfig extends Config {
return pluginsConfigSection;
}
public NetworkSettings getNetworkSettings() {
return networkSettings;
}
public WorldAliasSettings getWorldAliasSettings() {
return worldAliasSettings;
}

View File

@ -1,127 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.system.settings.network;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
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.settings.paths.key.Setting;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.console.PluginLogger;
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.util.Map;
import java.util.UUID;
/**
* Class for managing Config setting transfer from Bungee to Bukkit servers.
*
* @author Rsl1122
*/
@Singleton
@Deprecated
public class NetworkSettings {
private final Lazy<PlanConfig> config;
private final ServerSpecificSettings serverSpecificSettings;
private final Processing processing;
private final Lazy<DBSystem> dbSystem;
private final Lazy<ServerInfo> serverInfo;
private final PluginLogger logger;
private final ErrorHandler errorHandler;
@Inject
public NetworkSettings(
Lazy<PlanConfig> config,
ServerSpecificSettings serverSpecificSettings,
Processing processing,
Lazy<DBSystem> dbSystem,
Lazy<ServerInfo> serverInfo,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.config = config;
this.serverSpecificSettings = serverSpecificSettings;
this.processing = processing;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.logger = logger;
this.errorHandler = errorHandler;
}
public void loadSettingsFromDB() {
if (Check.isBungeeAvailable() || Check.isVelocityAvailable()) {
return;
}
PlanConfig planConfig = config.get();
if (planConfig.isFalse(PluginSettings.BUNGEE_COPY_CONFIG)) {
// Don't load settings if they are overridden.
return;
}
}
public void placeSettingsToDB() {
if (!Check.isBungeeAvailable() && !Check.isVelocityAvailable()) {
return;
}
}
private void addConfigValue(Map<String, Object> configValues, Setting setting, Object value) {
if (value != null) {
configValues.put(setting.getPath(), value);
}
}
private void addConfigValue(Map<String, Object> configValues, UUID serverUUID, Setting setting, Object value) {
if (value != null) {
configValues.put(serverUUID + ":" + setting.getPath(), value);
}
}
private void addServerSpecificValues(Map<String, Object> configValues) {
logger.debug("NetworkSettings: Adding Server-specific Config Values..");
for (UUID serverUUID : dbSystem.get().getDatabase().fetch().getServerUUIDs()) {
String theme = serverSpecificSettings.getString(serverUUID, DisplaySettings.THEME);
Integer port = serverSpecificSettings.getInt(serverUUID, WebserverSettings.PORT);
String name = serverSpecificSettings.getString(serverUUID, PluginSettings.SERVER_NAME);
if (!Verify.isEmpty(theme)) {
addConfigValue(configValues, serverUUID, DisplaySettings.THEME, theme);
}
if (port != null && port != 0) {
addConfigValue(configValues, serverUUID, WebserverSettings.PORT, port);
}
if (!Verify.isEmpty(name)) {
addConfigValue(configValues, serverUUID, PluginSettings.SERVER_NAME, name);
}
}
}
public ServerSpecificSettings getServerSpecificSettings() {
return serverSpecificSettings;
}
}

View File

@ -1,145 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.system.settings.network;
import com.djrapitops.plan.PlanPlugin;
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.settings.paths.key.Setting;
import com.djrapitops.plugin.logging.console.PluginLogger;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
/**
* Bungee Config manager for Server Settings such as:
* - WebServer Port
* - ServerName
* - Theme Base
*
* @author Rsl1122
*/
@Singleton
@Deprecated
public class ServerSpecificSettings {
private final Lazy<PlanPlugin> plugin;
private final Lazy<PlanConfig> config;
private final PluginLogger logger;
@Inject
public ServerSpecificSettings(
Lazy<PlanPlugin> plugin,
Lazy<PlanConfig> config,
PluginLogger logger
) {
this.plugin = plugin;
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();
if ("sender".equals(path)) {
continue;
}
String stringValue = setting.getValue();
Object value = getValue(stringValue);
String currentValue = planConfig.getString(path);
if (stringValue.equals(currentValue)) {
continue;
}
planConfig.set(path, value);
logger.debug(" " + path + ": " + value);
} catch (NullPointerException ignored) {
}
changedSomething = true;
}
if (changedSomething) {
planConfig.save();
logger.info("----------------------------------");
logger.info("The Received Bungee Settings changed the config values, restarting Plan..");
logger.info("----------------------------------");
plugin.get().reloadPlugin(true);
} else {
logger.debug("Settings up to date");
}
}
private Object getValue(String value) {
try {
return Integer.parseInt(value);
} catch (Exception ignored) {
}
if ("true".equalsIgnoreCase(value)) {
return true;
} else if ("false".equalsIgnoreCase(value)) {
return false;
}
// Value is a string
return value;
}
private String getPath(UUID serverUUID, Setting setting) {
String path = "Servers." + serverUUID;
if (setting.equals(WebserverSettings.PORT)) {
path += ".WebServerPort";
} else if (setting.equals(PluginSettings.SERVER_NAME)) {
path += ".ServerName";
} else if (setting.equals(DisplaySettings.THEME)) {
path += ".ThemeBase";
}
return path;
}
public boolean getBoolean(UUID serverUUID, Setting setting) {
String path = getPath(serverUUID, setting);
return config.get().getBoolean(path);
}
public String getString(UUID serverUUID, Setting setting) {
String path = getPath(serverUUID, setting);
return config.get().getString(path);
}
public Integer getInt(UUID serverUUID, Setting setting) {
String path = getPath(serverUUID, setting);
return config.get().getInteger(path);
}
public void set(UUID serverUUID, Setting setting, Object value) throws IOException {
String path = getPath(serverUUID, setting);
PlanConfig planConfig = config.get();
planConfig.set(path, value);
planConfig.save();
}
}

View File

@ -21,7 +21,6 @@ import com.djrapitops.plan.system.settings.paths.TimeSettings;
import com.djrapitops.plan.system.tasks.server.BootAnalysisTask;
import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import java.util.concurrent.TimeUnit;
@ -74,12 +73,6 @@ public abstract class ServerTaskSystem extends TaskSystem {
}
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
registerTask("Settings Load", new AbsRunnable() {
@Override
public void run() {
config.getNetworkSettings().loadSettingsFromDB();
}
}).runTaskAsynchronously();
registerTask(playersPageRefreshTask)
.runTaskTimerAsynchronously(TimeAmount.toTicks(5L, TimeUnit.MINUTES), TimeAmount.toTicks(5L, TimeUnit.MINUTES));
}

View File

@ -52,9 +52,9 @@ public class ConfigSettingKeyTest {
}
@Test
public void networkConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
public void proxyConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
PlanConfig planConfig = createConfig("bungeeconfig.yml");
Collection<Setting> settings = getNetworkSettings();
Collection<Setting> settings = getProxySettings();
hasValidDefaultValuesForAllSettings(planConfig, settings);
}
@ -97,7 +97,7 @@ public class ConfigSettingKeyTest {
return settings;
}
private Collection<Setting> getNetworkSettings() throws IllegalAccessException {
private Collection<Setting> getProxySettings() throws IllegalAccessException {
List<Setting> settings = new ArrayList<>();
for (Class settingKeyClass : new Class[]{
DatabaseSettings.class,
@ -135,7 +135,7 @@ public class ConfigSettingKeyTest {
}
private PlanConfig createConfig(File configFile) throws IOException {
PlanConfig config = new PlanConfig(configFile, null, null);
PlanConfig config = new PlanConfig(configFile, null);
config.save();
return config;
}

View File

@ -23,7 +23,6 @@ import com.djrapitops.plan.system.tasks.proxy.NetworkPageRefreshTask;
import com.djrapitops.plan.system.tasks.velocity.PingCountTimerVelocity;
import com.djrapitops.plan.system.tasks.velocity.VelocityTPSCountTimer;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import javax.inject.Inject;
@ -72,12 +71,6 @@ public class VelocityTaskSystem extends TaskSystem {
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.toTicks(1L, TimeUnit.SECONDS));
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.toTicks(5L, TimeUnit.MINUTES));
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
registerTask("Settings Save", new AbsRunnable() {
@Override
public void run() {
config.getNetworkSettings().placeSettingsToDB();
}
}).runTaskAsynchronously();
plugin.registerListener(pingCountTimer);
long startDelay = TimeAmount.toTicks(config.get(TimeSettings.PING_SERVER_ENABLE_DELAY), TimeUnit.MILLISECONDS);