From d6bfc52abcdbbf484c4516cc553a0d2ce2bb77f9 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 22 Nov 2021 10:49:30 +0000 Subject: [PATCH] Added false options to in_air, in_water, and is_sneaking --- .../conditions/conditions/ConditionInAir.kt | 17 ++++++++++++++++- .../conditions/conditions/ConditionInWater.kt | 17 ++++++++++++++++- .../conditions/ConditionIsSneaking.kt | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt index 7e07cc954..589756bc4 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt @@ -1,6 +1,7 @@ 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 @@ -20,6 +21,20 @@ class ConditionInAir: Condition("in_air") { } override fun isConditionMet(player: Player, config: JSONConfig): Boolean { - return player.location.block.isEmpty + return player.location.block.isEmpty == config.getBool("in_air") + } + + override fun validateConfig(config: JSONConfig): List { + val violations = mutableListOf() + + config.getBoolOrNull("in_air") + ?: violations.add( + ConfigViolation( + "in_air", + "You must specify if the player must be in air on on land!" + ) + ) + + return violations } } \ No newline at end of file diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInWater.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInWater.kt index dd92f07cc..42e47fe23 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInWater.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInWater.kt @@ -1,6 +1,7 @@ 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 @@ -24,6 +25,20 @@ class ConditionInWater: Condition("in_water") { } override fun isConditionMet(player: Player, config: JSONConfig): Boolean { - return player.isInWater + return player.isInWater == config.getBool("in_water") + } + + override fun validateConfig(config: JSONConfig): List { + val violations = mutableListOf() + + config.getBoolOrNull("in_water") + ?: violations.add( + ConfigViolation( + "in_water", + "You must specify if the player must be in water or not!" + ) + ) + + return violations } } \ No newline at end of file diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsSneaking.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsSneaking.kt index 0be528745..3291670d0 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsSneaking.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionIsSneaking.kt @@ -1,6 +1,7 @@ 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 @@ -20,6 +21,20 @@ class ConditionIsSneaking: Condition("is_sneaking") { } override fun isConditionMet(player: Player, config: JSONConfig): Boolean { - return player.isSprinting + return player.isSneaking == config.getBool("is_sneaking") + } + + override fun validateConfig(config: JSONConfig): List { + val violations = mutableListOf() + + config.getBoolOrNull("is_sneaking") + ?: violations.add( + ConfigViolation( + "is_sneaking", + "You must specify if the player must be sneaking or standing!" + ) + ) + + return violations } } \ No newline at end of file