From de1dab509b3d6263eb31a4a0a1fd06728c65b738 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 14 Oct 2023 14:13:04 +0100 Subject: [PATCH] Added is_passive --- .../com/willfp/libreforge/filters/Filters.kt | 2 ++ .../filters/impl/FilterIsPassive.kt | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 core/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterIsPassive.kt diff --git a/core/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt b/core/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt index 1157ba99d..6e60777ac 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt @@ -17,6 +17,7 @@ import com.willfp.libreforge.filters.impl.FilterFullyCharged import com.willfp.libreforge.filters.impl.FilterFullyGrown import com.willfp.libreforge.filters.impl.FilterIsBehindVictim import com.willfp.libreforge.filters.impl.FilterIsNPC +import com.willfp.libreforge.filters.impl.FilterIsPassive import com.willfp.libreforge.filters.impl.FilterItemDurabilityAbove import com.willfp.libreforge.filters.impl.FilterItemDurabilityBelow import com.willfp.libreforge.filters.impl.FilterItems @@ -100,5 +101,6 @@ object Filters : Registry>() { register(FilterVictimName) register(FilterItemDurabilityAbove) register(FilterItemDurabilityBelow) + register(FilterIsPassive) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterIsPassive.kt b/core/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterIsPassive.kt new file mode 100644 index 000000000..7b30d8eec --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterIsPassive.kt @@ -0,0 +1,24 @@ +package com.willfp.libreforge.filters.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.eco.util.NamespacedKeyUtils +import com.willfp.libreforge.NoCompileData +import com.willfp.libreforge.filters.Filter +import com.willfp.libreforge.triggers.TriggerData +import org.bukkit.entity.Boss +import org.bukkit.entity.Creature +import org.bukkit.entity.ElderGuardian +import org.bukkit.entity.Monster +import org.bukkit.persistence.PersistentDataType + +object FilterIsPassive : Filter("is_passive") { + override fun getValue(config: Config, data: TriggerData?, key: String): Boolean { + return config.getBool(key) + } + + override fun isMet(data: TriggerData, value: Boolean, compileData: NoCompileData): Boolean { + val entity = data.victim ?: return true + + return (entity is Creature && entity !is Monster) == value + } +}