9
0
mirror of https://github.com/Auxilor/EcoQuests.git synced 2026-01-04 15:41:38 +00:00

Added quests start display

This commit is contained in:
Auxilor
2023-08-08 21:14:27 +01:00
parent c74a429e73
commit f4600b2cde
11 changed files with 119 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import com.willfp.ecoquests.commands.CommandQuests
import com.willfp.ecoquests.gui.PreviousQuestsGUI
import com.willfp.ecoquests.gui.QuestsGUI
import com.willfp.ecoquests.quests.QuestCompleteDisplay
import com.willfp.ecoquests.quests.QuestStartDisplay
import com.willfp.ecoquests.quests.Quests
import com.willfp.ecoquests.tasks.Tasks
import com.willfp.libreforge.loader.LibreforgePlugin
@@ -35,7 +36,8 @@ class EcoQuestsPlugin : LibreforgePlugin() {
override fun loadListeners(): List<Listener> {
return listOf(
QuestCompleteDisplay(this)
QuestCompleteDisplay(this),
QuestStartDisplay(this)
)
}

View File

@@ -5,7 +5,7 @@ import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent
class PlayerCompleteQuestEvent(
class PlayerQuestCompleteEvent(
who: Player,
val quest: Quest
): PlayerEvent(who) {

View File

@@ -5,7 +5,7 @@ import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent
class PlayerStartQuestEvent(
class PlayerQuestStartEvent(
who: Player,
val quest: Quest
): PlayerEvent(who) {

View File

@@ -5,7 +5,7 @@ import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent
class PlayerCompleteTaskEvent(
class PlayerTaskCompleteEvent(
who: Player,
val task: Task
): PlayerEvent(who) {

View File

@@ -11,8 +11,8 @@ import com.willfp.eco.core.items.builder.modify
import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.formatEco
import com.willfp.ecoquests.api.event.PlayerCompleteQuestEvent
import com.willfp.ecoquests.api.event.PlayerStartQuestEvent
import com.willfp.ecoquests.api.event.PlayerQuestCompleteEvent
import com.willfp.ecoquests.api.event.PlayerQuestStartEvent
import com.willfp.ecoquests.tasks.Tasks
import com.willfp.libreforge.EmptyProvidedHolder
import com.willfp.libreforge.ViolationContext
@@ -29,6 +29,8 @@ class Quest(
) : KRegistrable {
val name = config.getFormattedString("name")
val announcesStart = config.getBool("announce-start")
private val guiItem = Items.lookup(config.getString("gui.item")).item
val slot = slot({ player, _ ->
@@ -107,7 +109,7 @@ class Quest(
startEffects?.trigger(player)
player.profile.write(hasStartedKey, true)
Bukkit.getPluginManager().callEvent(PlayerStartQuestEvent(player, this))
Bukkit.getPluginManager().callEvent(PlayerQuestStartEvent(player, this))
}
fun checkCompletion(player: Player): Boolean {
@@ -120,7 +122,7 @@ class Quest(
player.profile.write(hasCompletedKey, true)
rewards?.trigger(player)
Bukkit.getPluginManager().callEvent(PlayerCompleteQuestEvent(player, this))
Bukkit.getPluginManager().callEvent(PlayerQuestCompleteEvent(player, this))
return true
}

View File

@@ -3,7 +3,7 @@ package com.willfp.ecoquests.quests
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.sound.PlayableSound
import com.willfp.eco.util.toComponent
import com.willfp.ecoquests.api.event.PlayerCompleteQuestEvent
import com.willfp.ecoquests.api.event.PlayerQuestCompleteEvent
import net.kyori.adventure.title.Title
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
@@ -19,7 +19,7 @@ class QuestCompleteDisplay(
} else null
@EventHandler
fun handle(event: PlayerCompleteQuestEvent) {
fun handle(event: PlayerQuestCompleteEvent) {
val player = event.player
val quest = event.quest

View File

@@ -0,0 +1,65 @@
package com.willfp.ecoquests.quests
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.sound.PlayableSound
import com.willfp.eco.util.toComponent
import com.willfp.ecoquests.api.event.PlayerQuestStartEvent
import net.kyori.adventure.title.Title
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import java.time.Duration
class QuestStartDisplay(
private val plugin: EcoPlugin
) : Listener {
private val sound = if (plugin.configYml.getBool("quests.start.sound.enabled")) {
PlayableSound.create(
plugin.configYml.getSubsection("quests.start.sound")
)
} else null
@EventHandler
fun handle(event: PlayerQuestStartEvent) {
val player = event.player
val quest = event.quest
if (!quest.announcesStart) {
return
}
if (plugin.configYml.getBool("quests.start.message.enabled")) {
val rawMessage = plugin.configYml.getStrings("quests.start.message.message")
val formatted = quest.addPlaceholdersInto(
rawMessage,
player
)
formatted.forEach { player.sendMessage(it) }
}
if (plugin.configYml.getBool("quests.start.title.enabled")) {
val rawTitle = plugin.configYml.getString("quests.start.title.title")
val rawSubtitle = plugin.configYml.getString("quests.start.title.subtitle")
val formatted = quest.addPlaceholdersInto(
listOf(rawTitle, rawSubtitle),
player
)
player.showTitle(
Title.title(
formatted[0].toComponent(),
formatted[1].toComponent(),
Title.Times.times(
Duration.ofMillis((plugin.configYml.getDouble("quests.start.title.fade-in") * 1000).toLong()),
Duration.ofMillis((plugin.configYml.getDouble("quests.start.title.stay") * 1000).toLong()),
Duration.ofMillis((plugin.configYml.getDouble("quests.start.title.fade-out") * 1000).toLong())
)
)
)
}
sound?.playTo(player)
}
}

View File

@@ -9,7 +9,7 @@ import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.lineWrap
import com.willfp.eco.util.toNiceString
import com.willfp.ecoquests.api.event.PlayerCompleteTaskEvent
import com.willfp.ecoquests.api.event.PlayerTaskCompleteEvent
import com.willfp.ecoquests.quests.Quests
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.counters.Accumulator
@@ -102,7 +102,7 @@ class Task(
if (newXp >= requiredXp) {
player.profile.write(hasCompletedKey, true)
Bukkit.getPluginManager().callEvent(PlayerCompleteTaskEvent(player, this))
Bukkit.getPluginManager().callEvent(PlayerTaskCompleteEvent(player, this))
// Then check if any quests are now completed
for (quest in Quests.values()) {

View File

@@ -172,4 +172,34 @@ quests:
# Pitch between 0.5 and 2
pitch: 1.5
# The volume
volume: 1.0
start:
message:
enabled: true
message:
- "&f"
- " &#eacda3&lNEW QUEST: &f%quest%"
- "&f"
- " &#eacda3&lREWARDS:"
- "%rewards%"
- "&f"
title:
enabled: false
# Durations are in seconds
fade-in: 0.5
stay: 2
fade-out: 0.5
title: "&#eacda3&lNew Quest!"
subtitle: "&f%quest%"
sound:
# If a sound should be played
enabled: true
# The sound that should be played
sound: entity_player_levelup
# Pitch between 0.5 and 2
pitch: 1.9
# The volume
volume: 1.0

View File

@@ -7,6 +7,7 @@ gui:
tasks:
- break_100_stone
# The messages for the %rewards% placeholder in icons, messages, etc.
reward-messages:
- " &8» &r&f+2 %ecoskills_defense_name%"
@@ -14,6 +15,9 @@ reward-messages:
# Read https://plugins.auxilor.io/effects/configuring-an-effect
rewards: [ ]
# If the player should be told when they have started the quest.
announce-start: true
# A list of effects to run when the quest is started.
# Read https://plugins.auxilor.io/effects/configuring-an-effect
start-effects: [ ]

View File

@@ -7,6 +7,7 @@ gui:
tasks:
- break_100_stone
# The messages for the %rewards% placeholder in icons, messages, etc.
reward-messages:
- " &8» &r&f+2 %ecoskills_defense_name%"
@@ -14,6 +15,9 @@ reward-messages:
# Read https://plugins.auxilor.io/effects/configuring-an-effect
rewards: [ ]
# If the player should be told when they have started the quest.
announce-start: true
# A list of effects to run when the quest is started.
# Read https://plugins.auxilor.io/effects/configuring-an-effect
start-effects: [ ]