9
0
mirror of https://github.com/Auxilor/EcoQuests.git synced 2025-12-26 10:29:07 +00:00

Added placeholders

This commit is contained in:
Auxilor
2023-08-08 21:55:07 +01:00
parent af6b7a111a
commit 96870aee60
5 changed files with 61 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
package com.willfp.ecoquests
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.eco.core.placeholder.PlayerPlaceholder
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
import com.willfp.ecoquests.commands.CommandEcoQuests
import com.willfp.ecoquests.commands.CommandQuests
import com.willfp.ecoquests.gui.PreviousQuestsGUI
@@ -16,6 +18,20 @@ import org.bukkit.event.Listener
class EcoQuestsPlugin : LibreforgePlugin() {
override fun handleEnable() {
PlayerlessPlaceholder(this, "quests_amount") {
Quests.values().size.toString()
}
PlayerPlaceholder(this, "quests_completed") {
Quests.getCompletedQuests(it).size.toString()
}
PlayerPlaceholder(this, "quests_active") {
Quests.getActiveQuests(it).size.toString()
}
}
override fun handleReload() {
PreviousQuestsGUI.reload(this)
QuestsGUI.reload(this)

View File

@@ -20,7 +20,7 @@ object QuestsGUI {
fun reload(plugin: EcoPlugin) {
val questAreaComponent = QuestAreaComponent(plugin.configYml.getSubsection("gui.quest-area")) {
Quests.getCurrentlyActiveQuests(it)
Quests.getActiveQuests(it)
}
menu = menu(plugin.configYml.getInt("gui.rows")) {

View File

@@ -8,9 +8,12 @@ import com.willfp.eco.core.data.profile
import com.willfp.eco.core.gui.slot
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.builder.modify
import com.willfp.eco.core.placeholder.PlayerPlaceholder
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.toNiceString
import com.willfp.ecoquests.api.event.PlayerQuestCompleteEvent
import com.willfp.ecoquests.api.event.PlayerQuestStartEvent
import com.willfp.ecoquests.tasks.Tasks
@@ -19,6 +22,7 @@ import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.effects.Effects
import com.willfp.libreforge.effects.executors.impl.NormalExecutorFactory
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle.getDescription
import org.bukkit.Bukkit
import org.bukkit.entity.Player
@@ -79,6 +83,24 @@ class Quest(
ViolationContext(plugin, "quest $id start-conditions")
)
init {
PlayerPlaceholder(plugin, "quest_${id}_started") {
hasStarted(it).toNiceString()
}
PlayerPlaceholder(plugin, "quest_${id}_completed") {
hasCompleted(it).toNiceString()
}
PlayerlessPlaceholder(plugin, "quest_${id}_tasks") {
this.tasks.size.toNiceString()
}
PlayerPlaceholder(plugin, "quest_${id}_tasks_completed") {
this.tasks.count { t -> t.hasCompleted(it) }.toNiceString()
}
}
fun hasCompleted(player: Player): Boolean {
return player.profile.read(hasCompletedKey)
}

View File

@@ -21,7 +21,7 @@ object Quests : ConfigCategory("quest", "quests") {
fun values(): Collection<Quest> = registry.values()
fun getCurrentlyActiveQuests(player: Player): List<Quest> {
fun getActiveQuests(player: Player): List<Quest> {
return values()
.filter { it.hasStarted(player) }
.filterNot { it.hasCompleted(player) }

View File

@@ -5,6 +5,9 @@ import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import com.willfp.eco.core.data.profile
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.placeholder.PlayerPlaceholder
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.lineWrap
@@ -45,6 +48,24 @@ class Task(
}
}
init {
PlayerPlaceholder(plugin, "task_${id}_required_xp") {
getExperienceRequired(it).toNiceString()
}
PlayerPlaceholder(plugin, "task_${id}_xp") {
getExperience(it).toNiceString()
}
PlayerPlaceholder(plugin, "task_${id}_description") {
getDescription(it)
}
PlayerPlaceholder(plugin, "task_${id}_completed") {
hasCompleted(it).toNiceString()
}
}
override fun onRegister() {
for (counter in xpGainMethods) {
counter.bind(accumulator)