From b6d0b778dc8bde99313bf7d40f978c802554ee10 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 27 Nov 2021 15:00:15 +0000 Subject: [PATCH] Added ConditionIsStorm --- .../libreforge/conditions/Conditions.kt | 1 + .../conditions/conditions/ConditionIsStorm.kt | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsStorm.kt diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt index bd2deb119..13d8134ba 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt @@ -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. diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsStorm.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsStorm.kt new file mode 100644 index 000000000..009733280 --- /dev/null +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsStorm.kt @@ -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 { + val violations = mutableListOf() + + config.getBoolOrNull("is_storm") + ?: violations.add( + ConfigViolation( + "is_storm", + "You must specify if the player must be in a storm or not!" + ) + ) + + return violations + } +} \ No newline at end of file