From f522db1dba71441a2872fbfa53fab6746dd3cb95 Mon Sep 17 00:00:00 2001 From: Will FP Date: Sun, 26 Nov 2023 23:14:27 +0000 Subject: [PATCH] Added has_completed_advancement condition --- .../libreforge/conditions/Conditions.kt | 2 ++ .../impl/ConditionHasCompletedAdvancement.kt | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionHasCompletedAdvancement.kt 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 + } +}