From bfaf1c77915d07b5fb2ffb4be272bbb9679106b4 Mon Sep 17 00:00:00 2001 From: Roman Makeev <57789105+makeevrserg@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:06:21 +0000 Subject: [PATCH] fix advancements money event (#68) --- gradle.properties | 2 +- .../ru/astrainteractive/aspekt/di/CoreModule.kt | 17 +++++++++++++---- .../aspekt/plugin/PluginTranslation.kt | 6 +++--- .../event/MoneyAdvancementEvent.kt | 12 +++++++++--- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3c2788a..ce3b3db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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|makeevrserg@gmail.com makeevrserg.project.url=https://empireprojekt.ru diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/di/CoreModule.kt b/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/di/CoreModule.kt index b42f4e8..d5cd2df 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/di/CoreModule.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/di/CoreModule.kt @@ -3,6 +3,7 @@ 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 @@ -10,7 +11,8 @@ 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 @@ -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 @@ -77,7 +80,15 @@ interface CoreModule : Lifecycle { } override val economyProvider: Reloadable = 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 = Reloadable { @@ -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() } } } diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt b/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt index 90bfbf3..8007ea7 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt @@ -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()) diff --git a/modules/money-advancements/src/main/kotlin/ru/astrainteractive/aspekt/module/moneyadvancement/event/MoneyAdvancementEvent.kt b/modules/money-advancements/src/main/kotlin/ru/astrainteractive/aspekt/module/moneyadvancement/event/MoneyAdvancementEvent.kt index 7ce99f3..99036ec 100644 --- a/modules/money-advancements/src/main/kotlin/ru/astrainteractive/aspekt/module/moneyadvancement/event/MoneyAdvancementEvent.kt +++ b/modules/money-advancements/src/main/kotlin/ru/astrainteractive/aspekt/module/moneyadvancement/event/MoneyAdvancementEvent.kt @@ -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 @@ -16,7 +18,7 @@ class MoneyAdvancementEvent( economyProvider: Provider, kyoriComponentSerializerProvider: Provider, translationProvider: Provider -) : EventListener { +) : EventListener, Logger by JUtiltLogger("MoneyAdvancementEvent") { private val configuration by configurationProvider private val economy by economyProvider private val kyoriComponentSerializer by kyoriComponentSerializerProvider @@ -24,8 +26,12 @@ class MoneyAdvancementEvent( @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()