Skip to content

Commit

Permalink
fix advancements money event (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Aug 9, 2024
1 parent 048e236 commit bfaf1c7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ makeevrserg.java.ktarget=21
# Project
makeevrserg.project.name=AspeKt
makeevrserg.project.group=ru.astrainteractive.aspekt
makeevrserg.project.version.string=2.23.1
makeevrserg.project.version.string=2.23.2
makeevrserg.project.description=Essentials plugin for EmpireProjekt
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://empireprojekt.ru
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package ru.astrainteractive.aspekt.di
import kotlinx.serialization.StringFormat
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
import ru.astrainteractive.aspekt.plugin.PluginConfiguration
import ru.astrainteractive.aspekt.plugin.PluginTranslation
import ru.astrainteractive.astralibs.async.AsyncComponent
import ru.astrainteractive.astralibs.async.BukkitDispatchers
import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers
import ru.astrainteractive.astralibs.economy.EconomyProvider
import ru.astrainteractive.astralibs.economy.EconomyProviderFactory
import ru.astrainteractive.astralibs.economy.EssentialsEconomyProvider
import ru.astrainteractive.astralibs.economy.VaultEconomyProvider
import ru.astrainteractive.astralibs.event.EventListener
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
Expand All @@ -20,6 +22,7 @@ import ru.astrainteractive.astralibs.serialization.YamlStringFormat
import ru.astrainteractive.klibs.kdi.Lateinit
import ru.astrainteractive.klibs.kdi.Reloadable
import ru.astrainteractive.klibs.kdi.getValue
import java.util.UUID

interface CoreModule : Lifecycle {
val plugin: Lateinit<JavaPlugin>
Expand Down Expand Up @@ -77,7 +80,15 @@ interface CoreModule : Lifecycle {
}

override val economyProvider: Reloadable<EconomyProvider?> = Reloadable {
kotlin.runCatching { EconomyProviderFactory(plugin.value).create() }.getOrNull()
val pluginManager = Bukkit.getServer().pluginManager
// todo temp fix without astralibs
runCatching {
val vault = pluginManager.getPlugin("Vault") ?: error("Vault is not installed")
VaultEconomyProvider(plugin.value, vault).also { it.getBalance(UUID.randomUUID()) }
}.getOrNull() ?: kotlin.runCatching {
val essentials = pluginManager.getPlugin("Essentials") ?: error("Essentials is not installed")
EssentialsEconomyProvider(plugin.value, essentials).also { it.getBalance(UUID.randomUUID()) }
}.getOrNull()
}

override val kyoriComponentSerializer: Reloadable<KyoriComponentSerializer> = Reloadable {
Expand Down Expand Up @@ -105,13 +116,11 @@ interface CoreModule : Lifecycle {
override fun onEnable() {
inventoryClickEventListener.onEnable(plugin.value)
eventListener.onEnable(plugin.value)
economyProvider.reload()
}

override fun onReload() {
pluginConfig.reload()
translation.reload()
economyProvider.reload()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class PluginTranslation(
class MoneyAdvancement(
@SerialName("reload_complete")
private val challengeCompleted: StringDesc.Raw = StringDesc.Raw(
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили достижение-челлендж и получили нагруда: %money% монет"
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили достижение-челлендж и получили награду: %money% монет"
),
@SerialName("goal_completed")
private val goalCompleted: StringDesc.Raw = StringDesc.Raw(
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили целевое достижение и получили нагруда: %money% монет"
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили целевое достижение и получили награду: %money% монет"
),
@SerialName("task_completed")
private val taskCompleted: StringDesc.Raw = StringDesc.Raw(
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили достижение и получили нагруда: %money% монет"
"&7[&#DBB72BДОСТИЖЕНИЕ&7] Вы выполднили достижение и получили награду: %money% монет"
),
) {
fun challengeCompleted(money: Number) = challengeCompleted.replace("%money%", money.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ru.astrainteractive.aspekt.plugin.PluginTranslation
import ru.astrainteractive.astralibs.economy.EconomyProvider
import ru.astrainteractive.astralibs.event.EventListener
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
import ru.astrainteractive.astralibs.logging.JUtiltLogger
import ru.astrainteractive.astralibs.logging.Logger
import ru.astrainteractive.klibs.kdi.Provider
import ru.astrainteractive.klibs.kdi.getValue

Expand All @@ -16,16 +18,20 @@ class MoneyAdvancementEvent(
economyProvider: Provider<EconomyProvider?>,
kyoriComponentSerializerProvider: Provider<KyoriComponentSerializer>,
translationProvider: Provider<PluginTranslation>
) : EventListener {
) : EventListener, Logger by JUtiltLogger("MoneyAdvancementEvent") {
private val configuration by configurationProvider
private val economy by economyProvider
private val kyoriComponentSerializer by kyoriComponentSerializerProvider
private val translation by translationProvider

@EventHandler
fun onAdvancement(e: PlayerAdvancementDoneEvent) {
val economy = economy ?: return
val frame = e.advancement.display?.frame() ?: AdvancementDisplay.Frame.TASK
val economy = economy ?: run {
error { "#onAdvancement economy not found" }
return
}
val frame = e.advancement.display?.frame() ?: return
info { "#onAdvancement ${e.advancement.key} ${e.advancement.display?.title()}" }
when (frame) {
AdvancementDisplay.Frame.CHALLENGE -> with(kyoriComponentSerializer) {
val amount = configuration.advancementMoney.challenge.toDouble()
Expand Down

0 comments on commit bfaf1c7

Please sign in to comment.