Skip to content

Commit

Permalink
Added swept filter
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 3, 2024
1 parent 3ae7545 commit 70d7e38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.willfp.libreforge.filters.impl.FilterPlayerPlaced
import com.willfp.libreforge.filters.impl.FilterPotionEffect
import com.willfp.libreforge.filters.impl.FilterProjectiles
import com.willfp.libreforge.filters.impl.FilterSpawnerEntity
import com.willfp.libreforge.filters.impl.FilterSwept
import com.willfp.libreforge.filters.impl.FilterText
import com.willfp.libreforge.filters.impl.FilterTextContains
import com.willfp.libreforge.filters.impl.FilterThisItem
Expand Down Expand Up @@ -122,5 +123,6 @@ object Filters : Registry<Filter<*, *>>() {
register(FilterThisItem)
register(FilterEnchant)
register(FilterSpawnerEntity)
register(FilterSwept)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.willfp.libreforge.filters.impl

import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.filters.Filter
import com.willfp.libreforge.triggers.TriggerData
import org.bukkit.event.entity.EntityDamageEvent

object FilterSwept : Filter<NoCompileData, Boolean>("swept") {
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 cause = (data.event as? EntityDamageEvent)?.cause ?: return true
return cause == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK == value
}
}

0 comments on commit 70d7e38

Please sign in to comment.