diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filter.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filter.kt index 975ee030..f5e4d9e5 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filter.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filter.kt @@ -36,9 +36,7 @@ abstract class Filter( ): Boolean { val cfg = config.config - val isInverted = config.isInverted ?: return true - - return if (isInverted) { + return if (config.isInverted) { !isMet(data, getValue(cfg, data, "not_$id"), config.compileData) } else { isMet(data, getValue(cfg, data, id), config.compileData) diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/FilterBlock.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/FilterBlock.kt index 9d9c1e02..158223bb 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/FilterBlock.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/FilterBlock.kt @@ -10,21 +10,9 @@ import com.willfp.libreforge.triggers.TriggerData class FilterBlock internal constructor( val filter: Filter, override val config: Config, - override val compileData: T + override val compileData: T, + val isInverted: Boolean ) : Compiled { - val isInverted: Boolean? by lazy { - val cfg = config - - val regularPresent = cfg.has(filter.id) - val inversePresent = cfg.has("not_${filter.id}") - - if (!regularPresent && !inversePresent) { - null - } else { - inversePresent - } - } - fun isMet(data: TriggerData) = filter.isMet(data, this) } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt index e8aa002a..84734cb1 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt @@ -52,8 +52,13 @@ object Filters : Registry>() { val blocks = mutableListOf>() for (key in config.getKeys(false)) { - val filter = get(key) ?: get(key.removePrefix("not_")) ?: continue - blocks += makeBlock(filter, config, context) ?: continue + if (key.startsWith("not_")) { + val filter = get(key.removePrefix("not_")) ?: continue + blocks += makeBlock(filter, config, true, context) ?: continue + } else { + val filter = get(key) ?: continue + blocks += makeBlock(filter, config, false, context) ?: continue + } } return FilterList(blocks) @@ -62,6 +67,7 @@ object Filters : Registry>() { private fun makeBlock( filter: Filter, config: Config, + inverted: Boolean, context: ViolationContext ): FilterBlock? { if (filter.deprecationMessage != null) { @@ -77,14 +83,14 @@ object Filters : Registry>() { return null } - val configKey = if (config.has("not_${filter.id}")) { + val configKey = if (inverted) { "not_${filter.id}" } else { filter.id } val compileData = filter.makeCompileData(config, context, filter.getValue(config, null, configKey)) - return FilterBlock(filter, config, compileData) + return FilterBlock(filter, config, compileData, inverted) } init {