diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java b/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java index 1b961ab5..1951f536 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java @@ -23,13 +23,31 @@ public abstract class BaseConfig extends LoadableConfigWrapper { @NotNull final PluginLike plugin, final boolean removeUnused, @NotNull final ConfigType type) { + this(configName, plugin, removeUnused, type, true); + } + + /** + * Create new Base Config. + * + * @param plugin The plugin or extension. + * @param configName The config name (excluding extension). + * @param removeUnused If unused sections should be removed. + * @param type The config type. + * @param requiresChangeToSave If changes must be applied to save the config. + */ + protected BaseConfig(@NotNull final String configName, + @NotNull final PluginLike plugin, + final boolean removeUnused, + @NotNull final ConfigType type, + final boolean requiresChangeToSave) { super(Eco.getHandler().getConfigFactory().createUpdatableConfig( configName, plugin, "", plugin.getClass(), removeUnused, - type + type, + requiresChangeToSave )); } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java index 00666a93..c9515dc8 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java @@ -30,8 +30,13 @@ import java.util.Set; public interface Config extends Cloneable, PlaceholderInjectable { /** * Clears cache. + *

+ * Configs no longer have caches as they have in previous versions. */ - void clearCache(); + @Deprecated(since = "6.31.1", forRemoval = true) + default void clearCache() { + // Do nothing. + } /** * Convert the config into readable text. diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java b/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java index 033e7e32..7fc4a68a 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java @@ -20,13 +20,14 @@ public interface ConfigFactory { /** * Updatable config. * - * @param configName The name of the config - * @param plugin The plugin. - * @param subDirectoryPath The subdirectory path. - * @param source The class that owns the resource. - * @param removeUnused Whether keys not present in the default config should be removed on update. - * @param type The config type. - * @param updateBlacklist Substring of keys to not add/remove keys for. + * @param configName The name of the config + * @param plugin The plugin. + * @param subDirectoryPath The subdirectory path. + * @param source The class that owns the resource. + * @param removeUnused Whether keys not present in the default config should be removed on update. + * @param type The config type. + * @param updateBlacklist Substring of keys to not add/remove keys for. + * @param requiresChangesToSave If the config must be changed in order to save the config. * @return The config implementation. */ LoadableConfig createUpdatableConfig(@NotNull String configName, @@ -35,23 +36,26 @@ public interface ConfigFactory { @NotNull Class source, boolean removeUnused, @NotNull ConfigType type, + boolean requiresChangesToSave, @NotNull String... updateBlacklist); /** * Loadable config. * - * @param configName The name of the config - * @param plugin The plugin. - * @param subDirectoryPath The subdirectory path. - * @param source The class that owns the resource. - * @param type The config type. + * @param configName The name of the config + * @param plugin The plugin. + * @param subDirectoryPath The subdirectory path. + * @param source The class that owns the resource. + * @param type The config type. + * @param requiresChangesToSave If the config must be changed in order to save the config. * @return The config implementation. */ LoadableConfig createLoadableConfig(@NotNull String configName, @NotNull PluginLike plugin, @NotNull String subDirectoryPath, @NotNull Class source, - @NotNull ConfigType type); + @NotNull ConfigType type, + boolean requiresChangesToSave); /** * Create config. diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigWrapper.java b/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigWrapper.java index 669b1135..77ec4ebd 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigWrapper.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigWrapper.java @@ -19,7 +19,7 @@ import java.util.Set; * * @param The type of the handle. */ -@SuppressWarnings("MethodDoesntCallSuperMethod") +@SuppressWarnings({"MethodDoesntCallSuperMethod", "removal"}) public abstract class ConfigWrapper implements Config { /** * Configs from eco have an internal implementation, @@ -43,6 +43,7 @@ public abstract class ConfigWrapper implements Config { } @Override + @Deprecated(since = "6.31.1", forRemoval = true) public void clearCache() { handle.clearCache(); } diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/builder/AbstractItemStackBuilder.java b/eco-api/src/main/java/com/willfp/eco/core/items/builder/AbstractItemStackBuilder.java index 17fa4496..c55d7a88 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/builder/AbstractItemStackBuilder.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/builder/AbstractItemStackBuilder.java @@ -59,6 +59,10 @@ public abstract class AbstractItemStackBuilder) { injections.removeIf { placeholders.any { placeholder -> it.identifier == placeholder.identifier } } injections.addAll(placeholders) - this.clearCache() } override fun getInjectedPlaceholders(): List { @@ -177,7 +167,6 @@ open class EcoConfig( override fun clearInjectedPlaceholders() { injections.clear() - this.clearCache() } override fun toMap(): MutableMap { diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt index 1c73f1e2..aeb16f4d 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt @@ -28,13 +28,15 @@ object EcoConfigFactory : ConfigFactory { plugin: PluginLike, subDirectoryPath: String, source: Class<*>, - type: ConfigType + type: ConfigType, + requiresChangesToSave: Boolean ): LoadableConfig = EcoLoadableConfig( type, configName, plugin, subDirectoryPath, - source + source, + requiresChangesToSave ) override fun createUpdatableConfig( @@ -44,6 +46,7 @@ object EcoConfigFactory : ConfigFactory { source: Class<*>, removeUnused: Boolean, type: ConfigType, + requiresChangesToSave: Boolean, vararg updateBlacklist: String ): LoadableConfig = EcoUpdatableConfig( type, @@ -52,6 +55,7 @@ object EcoConfigFactory : ConfigFactory { subDirectoryPath, source, removeUnused, + requiresChangesToSave, *updateBlacklist ) } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt index 64609659..f3de9114 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt @@ -19,7 +19,8 @@ open class EcoLoadableConfig( configName: String, private val plugin: PluginLike, private val subDirectoryPath: String, - val source: Class<*> + val source: Class<*>, + private val requiresChangesToSave: Boolean ) : EcoConfig(type), LoadableConfig { private val configFile: File private val name: String = "$configName.${type.extension}" @@ -57,8 +58,10 @@ open class EcoLoadableConfig( @Throws(IOException::class) override fun save() { - if (!hasChanged) { // In order to preserve comments - return + if (requiresChangesToSave) { + if (!hasChanged) { // In order to preserve comments + return + } } if (configFile.delete()) { diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt index 9ada9777..27b5475b 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt @@ -14,12 +14,12 @@ open class EcoUpdatableConfig( subDirectoryPath: String, source: Class<*>, private val removeUnused: Boolean, + requiresChangesToSave: Boolean, vararg updateBlacklist: String -) : EcoLoadableConfig(type, configName, plugin, subDirectoryPath, source) { +) : EcoLoadableConfig(type, configName, plugin, subDirectoryPath, source, requiresChangesToSave) { private val updateBlacklist = mutableListOf(*updateBlacklist) fun update() { - super.clearCache() this.init(configFile) val newConfig = configInJar ?: return if (newConfig.getKeys(true) == this.getKeys(true)) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt index 89c57f56..1347b66c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt @@ -10,5 +10,6 @@ class DataYml( "data", plugin, false, - ConfigType.YAML + ConfigType.YAML, + false )