From d8f98945e2ab03fd5e4a099ec75d359ef05aad75 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 8 Oct 2023 14:23:55 +1000 Subject: [PATCH] Refactor ConfigurationProvider --- .../com/viaversion/viaversion/api/ViaAPI.java | 2 +- .../viaversion/viaversion/api/ViaManager.java | 9 ++++ .../viaversion/api/configuration/Config.java | 53 +++++++++++++++++++ .../configuration/ConfigurationProvider.java | 30 +++++------ .../api/configuration/ViaVersionConfig.java | 2 +- .../viaversion/api/platform/ViaPlatform.java | 12 ++--- .../viaversion/ViaVersionPlugin.java | 5 -- .../bukkit/platform/BukkitViaConfig.java | 2 +- .../viaversion/viaversion/BungeePlugin.java | 6 --- .../bungee/platform/BungeeViaConfig.java | 2 +- .../service/ProtocolDetectorService.java | 7 +-- .../viaversion/viaversion/ViaManagerImpl.java | 8 +++ .../commands/defaultsubs/AutoTeamSubCmd.java | 8 +-- .../commands/defaultsubs/DontBugMeSubCmd.java | 10 ++-- .../commands/defaultsubs/ReloadSubCmd.java | 2 +- .../configuration/AbstractViaConfig.java | 7 +-- .../ConfigurationProviderImpl.java | 46 ++++++++++++++++ .../viaversion/viaversion/util/Config.java | 23 ++++---- .../viaversion/viaversion/util/DumpUtil.java | 2 +- .../viaversion/common/dummy/TestPlatform.java | 6 --- .../viaversion/viaversion/SpongePlugin.java | 6 --- .../sponge/platform/SpongeViaConfig.java | 2 +- .../viaversion/viaversion/VelocityPlugin.java | 6 --- .../velocity/platform/VelocityViaConfig.java | 2 +- .../service/ProtocolDetectorService.java | 5 +- 25 files changed, 170 insertions(+), 93 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/configuration/Config.java create mode 100644 common/src/main/java/com/viaversion/viaversion/configuration/ConfigurationProviderImpl.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index a3eb3e816..1cfd79f69 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -63,7 +63,7 @@ public interface ViaAPI { * @return API version incremented with meaningful API changes */ default int apiVersion() { - return 20; + return 21; } /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java index 17faa9b14..d0dcea225 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api; import com.viaversion.viaversion.api.command.ViaVersionCommand; +import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.connection.ConnectionManager; import com.viaversion.viaversion.api.debug.DebugHandler; import com.viaversion.viaversion.api.platform.ViaInjector; @@ -91,6 +92,13 @@ public interface ViaManager { */ Scheduler getScheduler(); + /** + * Returns the configuration provider. + * + * @return the configuration provider + */ + ConfigurationProvider getConfigurationProvider(); + /** * If debug is enabled, packets and other otherwise suppressed warnings will be logged. * @@ -138,4 +146,5 @@ public interface ViaManager { * @return whether the manager has been initialized */ boolean isInitialized(); + } diff --git a/api/src/main/java/com/viaversion/viaversion/api/configuration/Config.java b/api/src/main/java/com/viaversion/viaversion/api/configuration/Config.java new file mode 100644 index 000000000..9ad1f1287 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/configuration/Config.java @@ -0,0 +1,53 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2023 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.configuration; + +import java.util.Map; + +public interface Config { + + /** + * Reloads the config + */ + void reload(); + + /** + * Saves the config + */ + void save(); + + /** + * Sets the specified path to the given value. + * + * @param path Path of the object to set. + * @param value New value to set the path to + */ + void set(String path, Object value); + + /** + * Get all the configuration values + * + * @return Map with key-values + */ + Map getValues(); +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/configuration/ConfigurationProvider.java b/api/src/main/java/com/viaversion/viaversion/api/configuration/ConfigurationProvider.java index 75cdfb270..12c72525d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/configuration/ConfigurationProvider.java +++ b/api/src/main/java/com/viaversion/viaversion/api/configuration/ConfigurationProvider.java @@ -22,32 +22,26 @@ */ package com.viaversion.viaversion.api.configuration; -import java.util.Map; +import java.util.Collection; public interface ConfigurationProvider { /** - * Sets the specified path to the given value. + * Registers a config to be saved or reloaded when {@link #reloadConfigs()} is called. * - * @param path Path of the object to set. - * @param value New value to set the path to + * @param config the config to register */ - void set(String path, Object value); + void register(Config config); /** - * Saves the config - */ - void saveConfig(); - - /** - * Reloads the config - */ - void reloadConfig(); - - /** - * Get all the configuration values + * Returns all registered configs. * - * @return Map with key-values + * @return unmodifiable collection of all registered configs */ - Map getValues(); + Collection configs(); + + /** + * Reloads the configuration files. + */ + void reloadConfigs(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java index 5e00f8b80..59f62fbc4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java +++ b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java @@ -30,7 +30,7 @@ import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions; import it.unimi.dsi.fastutil.ints.IntSet; import org.checkerframework.checker.nullness.qual.Nullable; -public interface ViaVersionConfig { +public interface ViaVersionConfig extends Config { /** * Get if the plugin should check for updates diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java index 22ee5c98b..1f575e2c5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.platform; import com.google.gson.JsonObject; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.configuration.ConfigurationProvider; @@ -180,13 +181,10 @@ public interface ViaPlatform { */ ViaVersionConfig getConf(); - /** - * Get the backend configuration provider for this platform. - * (On some platforms this returns the same as getConf()) - * - * @return The configuration provider - */ - ConfigurationProvider getConfigurationProvider(); + @Deprecated/*(forRemoval = true)*/ + default ConfigurationProvider getConfigurationProvider() { + return Via.getManager().getConfigurationProvider(); + } /** * Get ViaVersions's data folder. diff --git a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java index 3fd3ff155..1e10ef095 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java @@ -221,11 +221,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform return Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled(); } - @Override - public ConfigurationProvider getConfigurationProvider() { - return conf; - } - @Override public void onReload() { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java index b85e3bb52..bbccc84f6 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java @@ -36,7 +36,7 @@ public class BukkitViaConfig extends AbstractViaConfig { public BukkitViaConfig() { super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml")); - reloadConfig(); + reload(); } @Override diff --git a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java index a474f4189..9d74144eb 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java +++ b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java @@ -22,7 +22,6 @@ import com.google.gson.JsonObject; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.command.ViaCommandSender; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.platform.UnsupportedSoftware; import com.viaversion.viaversion.api.platform.ViaServerProxyPlatform; @@ -176,11 +175,6 @@ public class BungeePlugin extends Plugin implements ViaServerProxyPlatform servers = ((BungeeViaConfig) Via.getConfig()).getBungeeServerProtocols(); + final BungeeViaConfig config = (BungeeViaConfig) Via.getConfig(); + if (config.isBungeePingSave()) { + final Map servers = config.getBungeeServerProtocols(); final Integer protocol = servers.get(serverName); if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { return; @@ -57,7 +58,7 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi synchronized (Via.getPlatform().getConfigurationProvider()) { servers.put(serverName, serverPing.getVersion().getProtocol()); } - Via.getPlatform().getConfigurationProvider().saveConfig(); + config.save(); } }); } diff --git a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index ff0142339..eea819cd2 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -19,6 +19,7 @@ package com.viaversion.viaversion; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.ViaManager; +import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.connection.ConnectionManager; import com.viaversion.viaversion.api.debug.DebugHandler; import com.viaversion.viaversion.api.platform.PlatformTask; @@ -32,6 +33,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import com.viaversion.viaversion.api.scheduler.Scheduler; import com.viaversion.viaversion.commands.ViaCommandHandler; +import com.viaversion.viaversion.configuration.ConfigurationProviderImpl; import com.viaversion.viaversion.connection.ConnectionManagerImpl; import com.viaversion.viaversion.debug.DebugHandlerImpl; import com.viaversion.viaversion.protocol.ProtocolManagerImpl; @@ -53,6 +55,7 @@ import java.util.regex.Pattern; public class ViaManagerImpl implements ViaManager { private final ProtocolManagerImpl protocolManager = new ProtocolManagerImpl(); private final ConnectionManager connectionManager = new ConnectionManagerImpl(); + private final ConfigurationProvider configurationProvider = new ConfigurationProviderImpl(); private final DebugHandler debugHandler = new DebugHandlerImpl(); private final ViaProviders providers = new ViaProviders(); private final Scheduler scheduler = new TaskScheduler(); @@ -306,6 +309,11 @@ public class ViaManagerImpl implements ViaManager { return scheduler; } + @Override + public ConfigurationProvider getConfigurationProvider() { + return configurationProvider; + } + /** * Returns a mutable set of self-added subplatform version strings. * This set is expanded by the subplatform itself (e.g. ViaBackwards), and may not contain all running ones. diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java index 231a790f0..d8db1cea1 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.commands.defaultsubs; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; +import com.viaversion.viaversion.util.Config; public class AutoTeamSubCmd extends ViaSubCommand { @Override @@ -35,11 +35,11 @@ public class AutoTeamSubCmd extends ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider(); boolean newValue = !Via.getConfig().isAutoTeam(); - provider.set("auto-team", newValue); - provider.saveConfig(); + final Config config = (Config) Via.getConfig(); + config.set("auto-team", newValue); + config.save(); sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players")); sendMessage(sender, "&6All players will need to re-login for the change to take place."); diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java index c4ccc8a4c..284b2ac61 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.commands.defaultsubs; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; +import com.viaversion.viaversion.api.configuration.ViaVersionConfig; public class DontBugMeSubCmd extends ViaSubCommand { @@ -36,11 +36,11 @@ public class DontBugMeSubCmd extends ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider(); - boolean newValue = !Via.getConfig().isCheckForUpdates(); + final ViaVersionConfig config = Via.getConfig(); + boolean newValue = !config.isCheckForUpdates(); - Via.getConfig().setCheckForUpdates(newValue); - provider.saveConfig(); + config.setCheckForUpdates(newValue); + config.save(); sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot ")); return true; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java index 9cbe02de8..919f2db16 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java @@ -34,7 +34,7 @@ public class ReloadSubCmd extends ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - Via.getPlatform().getConfigurationProvider().reloadConfig(); + Via.getPlatform().getConfigurationProvider().reloadConfigs(); sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart."); return true; } diff --git a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java index 384c4dddb..3b8d637ef 100644 --- a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java +++ b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java @@ -91,13 +91,14 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf private boolean cache1_17Light; private Map chatTypeFormats; - protected AbstractViaConfig(File configFile) { + protected AbstractViaConfig(final File configFile) { super(configFile); + Via.getManager().getConfigurationProvider().register(this); } @Override - public void reloadConfig() { - super.reloadConfig(); + public void reload() { + super.reload(); loadFields(); } diff --git a/common/src/main/java/com/viaversion/viaversion/configuration/ConfigurationProviderImpl.java b/common/src/main/java/com/viaversion/viaversion/configuration/ConfigurationProviderImpl.java new file mode 100644 index 000000000..3861c5081 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/configuration/ConfigurationProviderImpl.java @@ -0,0 +1,46 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2023 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.configuration; + +import com.viaversion.viaversion.api.configuration.Config; +import com.viaversion.viaversion.api.configuration.ConfigurationProvider; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class ConfigurationProviderImpl implements ConfigurationProvider { + private final List configs = new ArrayList<>(); + + @Override + public void register(final Config config) { + configs.add(config); + } + + @Override + public Collection configs() { + return Collections.unmodifiableCollection(configs); + } + + @Override + public void reloadConfigs() { + for (final Config config : configs) { + config.reload(); + } + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index 4653815ee..e0449dc91 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.util; import com.google.gson.JsonElement; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.compatibility.YamlCompat; import com.viaversion.viaversion.compatibility.unsafe.Yaml1Compat; import com.viaversion.viaversion.compatibility.unsafe.Yaml2Compat; @@ -40,7 +39,7 @@ import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; @SuppressWarnings("VulnerableCodeUsages") -public abstract class Config implements ConfigurationProvider { +public abstract class Config { private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion1() ? new Yaml1Compat() : new Yaml2Compat(); private static final ThreadLocal YAML = ThreadLocal.withInitial(() -> { DumperOptions options = new DumperOptions(); @@ -56,7 +55,7 @@ public abstract class Config implements ConfigurationProvider { /** * Create a new Config instance, this will *not* load the config by default. - * To load config see {@link #reloadConfig()} + * To load config see {@link #reload()} * * @param configFile The location of where the config is loaded/saved. */ @@ -116,14 +115,14 @@ public abstract class Config implements ConfigurationProvider { // Call Handler handleConfig(defaults); // Save - saveConfig(location, defaults); + save(location, defaults); return defaults; } protected abstract void handleConfig(Map config); - public synchronized void saveConfig(File location, Map config) { + public synchronized void save(File location, Map config) { try { commentStore.writeComments(YAML.get().dump(config), location); } catch (IOException e) { @@ -133,28 +132,24 @@ public abstract class Config implements ConfigurationProvider { public abstract List getUnsupportedOptions(); - @Override public void set(String path, Object value) { config.put(path, value); } - @Override - public void saveConfig() { + public void save() { this.configFile.getParentFile().mkdirs(); - saveConfig(this.configFile, this.config); + save(this.configFile, this.config); } - public void saveConfig(final File file) { - saveConfig(file, this.config); + public void save(final File file) { + save(file, this.config); } - @Override - public void reloadConfig() { + public void reload() { this.configFile.getParentFile().mkdirs(); this.config = new ConcurrentSkipListMap<>(loadConfig(this.configFile)); } - @Override public Map getValues() { return this.config; } diff --git a/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java b/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java index 7d574a0af..ed776df05 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java @@ -65,7 +65,7 @@ public final class DumpUtil { com.viaversion.viaversion.util.VersionInfo.getImplementationVersion(), Via.getManager().getSubPlatforms() ); - final Map configuration = Via.getPlatform().getConfigurationProvider().getValues(); + final Map configuration = ((Config) Via.getConfig()).getValues(); final DumpTemplate template = new DumpTemplate(version, configuration, Via.getPlatform().getDump(), Via.getManager().getInjector().getDump(), getPlayerSample(playerToSample)); final CompletableFuture result = new CompletableFuture<>(); Via.getPlatform().runAsync(() -> { diff --git a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java index 125a3a49b..383341a54 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java +++ b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java @@ -21,7 +21,6 @@ import com.google.gson.JsonObject; import com.viaversion.viaversion.ViaAPIBase; import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.command.ViaCommandSender; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.platform.ViaPlatform; @@ -118,11 +117,6 @@ public final class TestPlatform implements ViaPlatform { return testConfig; } - @Override - public ConfigurationProvider getConfigurationProvider() { - return null; - } - @Override public File getDataFolder() { return null; diff --git a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java index decc7ed08..1ee2fbede 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java @@ -21,7 +21,6 @@ import com.google.gson.JsonObject; import com.google.inject.Inject; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.dump.PluginInfo; @@ -193,11 +192,6 @@ public class SpongePlugin implements ViaPlatform { return true; } - @Override - public ConfigurationProvider getConfigurationProvider() { - return conf; - } - @Override public File getDataFolder() { return configDir.toFile(); diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java index c02ca6785..fd3891d33 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java @@ -30,7 +30,7 @@ public class SpongeViaConfig extends AbstractViaConfig { public SpongeViaConfig(File configFile) { super(new File(configFile, "config.yml")); - reloadConfig(); + reload(); } @Override diff --git a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java index c6ae351b6..6c554535a 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java @@ -29,7 +29,6 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; -import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.platform.ViaServerProxyPlatform; import com.viaversion.viaversion.dump.PluginInfo; @@ -193,11 +192,6 @@ public class VelocityPlugin implements ViaServerProxyPlatform { return true; } - @Override - public ConfigurationProvider getConfigurationProvider() { - return conf; - } - @Override public File getDataFolder() { return configDir.toFile(); diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java index 6426e6bf9..f6388db56 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java @@ -34,7 +34,7 @@ public class VelocityViaConfig extends AbstractViaConfig { public VelocityViaConfig(File configFile) { super(new File(configFile, "config.yml")); - reloadConfig(); + reload(); } @Override diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java index 87f5d67b9..2ded93d17 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java @@ -63,7 +63,8 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi setProtocolVersion(serverName, serverPing.getVersion().getProtocol()); - if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) { + final VelocityViaConfig config = (VelocityViaConfig) Via.getConfig(); + if (config.isVelocityPingSave()) { final Map servers = configuredServers(); final Integer protocol = servers.get(serverName); if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { @@ -74,7 +75,7 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi synchronized (Via.getPlatform().getConfigurationProvider()) { servers.put(serverName, serverPing.getVersion().getProtocol()); } - Via.getPlatform().getConfigurationProvider().saveConfig(); + config.save(); } }); }