Skip to content

Commit

Permalink
Added light_level_below condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Dec 8, 2023
1 parent 07c3641 commit 08c9b81
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.willfp.libreforge.conditions.impl.ConditionItemLevelEquals
import com.willfp.libreforge.conditions.impl.ConditionItemPointsAbove
import com.willfp.libreforge.conditions.impl.ConditionItemPointsBelow
import com.willfp.libreforge.conditions.impl.ConditionItemPointsEqual
import com.willfp.libreforge.conditions.impl.ConditionLightLevelBelow
import com.willfp.libreforge.conditions.impl.ConditionNearEntity
import com.willfp.libreforge.conditions.impl.ConditionOnFire
import com.willfp.libreforge.conditions.impl.ConditionOnGround
Expand Down Expand Up @@ -208,5 +209,6 @@ object Conditions : Registry<Condition<*>>() {
register(ConditionItemDataEquals)
register(ConditionIsOp)
register(ConditionHasCompletedAdvancement)
register(ConditionLightLevelBelow)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.willfp.libreforge.conditions.impl

import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import com.willfp.libreforge.getProvider
import com.willfp.libreforge.points
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack

object ConditionLightLevelBelow : Condition<NoCompileData>("light_level_below") {
override val arguments = arguments {
require("level", "You must specify maximum light level!")
}

override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val location = dispatcher.location ?: return false

val level = config.getIntFromExpression("level", dispatcher.get())

return location.block.lightLevel <= level
}
}

0 comments on commit 08c9b81

Please sign in to comment.