diff --git a/core/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt b/core/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt index 059e71957..c56fdf2ae 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/conditions/Conditions.kt @@ -23,6 +23,7 @@ import com.willfp.libreforge.conditions.impl.ConditionBelowXPLevel import com.willfp.libreforge.conditions.impl.ConditionBelowY import com.willfp.libreforge.conditions.impl.ConditionCanAffordPrice import com.willfp.libreforge.conditions.impl.ConditionGlobalPointsEqual +import com.willfp.libreforge.conditions.impl.ConditionHasCompletedAdvancement import com.willfp.libreforge.conditions.impl.ConditionHasItem import com.willfp.libreforge.conditions.impl.ConditionHasItemData import com.willfp.libreforge.conditions.impl.ConditionHasPermission @@ -206,5 +207,6 @@ object Conditions : Registry>() { register(ConditionHasItemData) register(ConditionItemDataEquals) register(ConditionIsOp) + register(ConditionHasCompletedAdvancement) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionHasCompletedAdvancement.kt b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionHasCompletedAdvancement.kt new file mode 100644 index 000000000..5b746e841 --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionHasCompletedAdvancement.kt @@ -0,0 +1,36 @@ +package com.willfp.libreforge.conditions.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.eco.util.containsIgnoreCase +import com.willfp.eco.util.safeNamespacedKeyOf +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 org.bukkit.Registry +import org.bukkit.advancement.Advancement +import org.bukkit.entity.LivingEntity +import org.bukkit.entity.Player + +object ConditionHasCompletedAdvancement : Condition("has_completed_advancement") { + override val arguments = arguments { + require("advancement", "You must specify the advancement!") + } + + override fun isMet( + dispatcher: Dispatcher<*>, + config: Config, + holder: ProvidedHolder, + compileData: NoCompileData + ): Boolean { + val player = dispatcher.get() ?: return false + + val advancement = Registry.ADVANCEMENT.get( + safeNamespacedKeyOf(config.getString("advancement")) ?: return false + ) ?: return false + + return player.getAdvancementProgress(advancement).isDone + } +}