-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added has_completed_advancement condition
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionHasCompletedAdvancement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |