Skip to content

Commit

Permalink
Added enchant filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Exanthiax committed May 8, 2024
1 parent 1808d9a commit 1e480cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.willfp.libreforge.filters.impl.FilterAboveHealthPercent
import com.willfp.libreforge.filters.impl.FilterAdvancements
import com.willfp.libreforge.filters.impl.FilterBlocks
import com.willfp.libreforge.filters.impl.FilterDamageCause
import com.willfp.libreforge.filters.impl.FilterEnchant
import com.willfp.libreforge.filters.impl.FilterEntities
import com.willfp.libreforge.filters.impl.FilterFromSpawner
import com.willfp.libreforge.filters.impl.FilterFullyCharged
Expand Down Expand Up @@ -118,5 +119,6 @@ object Filters : Registry<Filter<*, *>>() {
register(FilterIsExpressionTrue)
register(FilterAdvancements)
register(FilterThisItem)
register(FilterEnchant)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.enchantment.EnchantItemEvent

object FilterEnchant : Filter<NoCompileData, Collection<String>>("enchant") {
override fun getValue(config: Config, data: TriggerData?, key: String): Collection<String> {
return config.getStrings(key).map(String::uppercase)
}

override fun isMet(data: TriggerData, value: Collection<String>, compileData: NoCompileData): Boolean {
val event = data.event as? EnchantItemEvent ?: return true
val enchants = event.enchantsToAdd.keys.map { it.key.key.uppercase() }
return value.any { it in enchants }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object TriggerEnchantItem : Trigger("enchant_item") {
override val parameters = setOf(
TriggerParameter.PLAYER,
TriggerParameter.LOCATION,
TriggerParameter.EVENT,
TriggerParameter.ITEM
)

Expand All @@ -24,6 +25,7 @@ object TriggerEnchantItem : Trigger("enchant_item") {
TriggerData(
player = player,
item = item,
event = event,
value = event.expLevelCost.toDouble()
)
)
Expand Down

0 comments on commit 1e480cb

Please sign in to comment.