Skip to content

Commit

Permalink
Revert "Filters now accept both regular and inverted at the same time"
Browse files Browse the repository at this point in the history
This reverts commit 2b2d2ad.
  • Loading branch information
WillFP committed Aug 23, 2024
1 parent 6f1bf20 commit 898eef0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ abstract class Filter<T, V>(
): Boolean {
val cfg = config.config

val types = config.types
val results = mutableSetOf<Boolean>()
val isInverted = config.isInverted ?: return true

if (FilterType.REGULAR in types) {
results += isMet(data, getValue(cfg, data, id), config.compileData)
return if (isInverted) {
!isMet(data, getValue(cfg, data, "not_$id"), config.compileData)
} else {
isMet(data, getValue(cfg, data, id), config.compileData)
}

if (FilterType.INVERTED in types) {
results += !isMet(data, getValue(cfg, data, "not_$id"), config.compileData)
}

return results.all { it }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.willfp.libreforge.filters
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.Compiled
import com.willfp.libreforge.triggers.TriggerData
import java.util.EnumSet

/**
* A single filter config block.
Expand All @@ -13,23 +12,17 @@ class FilterBlock<T, V> internal constructor(
override val config: Config,
override val compileData: T
) : Compiled<T> {
val types: EnumSet<FilterType> by lazy {
val isInverted: Boolean? by lazy {
val cfg = config

val regularPresent = cfg.has(filter.id)
val inversePresent = cfg.has("not_${filter.id}")

val inversions = mutableSetOf<FilterType>()

if (regularPresent) {
inversions.add(FilterType.REGULAR)
}

if (inversePresent) {
inversions.add(FilterType.INVERTED)
if (!regularPresent && !inversePresent) {
null
} else {
inversePresent
}

EnumSet.copyOf(inversions)
}

fun isMet(data: TriggerData) =
Expand Down

This file was deleted.

0 comments on commit 898eef0

Please sign in to comment.