Skip to content

Commit

Permalink
Added ConditionIsStorm
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 27, 2021
1 parent be7350d commit b6d0b77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Conditions {
val IS_SNEAKING: Condition = ConditionIsSneaking()
val IN_AIR: Condition = ConditionInAir()
val IS_NIGHT: Condition = ConditionIsNight()
val IS_STORM: Condition = ConditionIsStorm()

/**
* Get condition matching id.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.willfp.libreforge.conditions.conditions

import com.willfp.eco.core.config.interfaces.JSONConfig
import com.willfp.libreforge.ConfigViolation
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.updateEffects
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.weather.WeatherChangeEvent

class ConditionIsStorm: Condition("is_storm") {
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
fun handle(event: WeatherChangeEvent) {
for (player in event.world.players) {
player.updateEffects()
}
}

override fun isConditionMet(player: Player, config: JSONConfig): Boolean {
return player.world.hasStorm() == config.getBool("is_storm")
}

override fun validateConfig(config: JSONConfig): List<ConfigViolation> {
val violations = mutableListOf<ConfigViolation>()

config.getBoolOrNull("is_storm")
?: violations.add(
ConfigViolation(
"is_storm",
"You must specify if the player must be in a storm or not!"
)
)

return violations
}
}

0 comments on commit b6d0b77

Please sign in to comment.