Skip to content

Commit

Permalink
Added has_completed_advancement condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 26, 2023
1 parent 4902a62 commit f522db1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -206,5 +207,6 @@ object Conditions : Registry<Condition<*>>() {
register(ConditionHasItemData)
register(ConditionItemDataEquals)
register(ConditionIsOp)
register(ConditionHasCompletedAdvancement)
}
}
Original file line number Diff line number Diff line change
@@ -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<NoCompileData>("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<Player>() ?: return false

val advancement = Registry.ADVANCEMENT.get(
safeNamespacedKeyOf(config.getString("advancement")) ?: return false
) ?: return false

return player.getAdvancementProgress(advancement).isDone
}
}

0 comments on commit f522db1

Please sign in to comment.