diff --git a/gradle.properties b/gradle.properties index 9b38731..a1e0c01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ makeevrserg.java.ktarget=17 # Project makeevrserg.project.name=AspeKt makeevrserg.project.group=ru.astrainteractive.aspekt -makeevrserg.project.version.string=2.5.3 +makeevrserg.project.version.string=2.6.0 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/plugin/src/main/kotlin/ru/astrainteractive/aspekt/AspeKt.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/AspeKt.kt index 1cc00d2..2a263bc 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/AspeKt.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/AspeKt.kt @@ -63,6 +63,7 @@ class AspeKt : JavaPlugin() { rootModule.translation.reload() rootModule.menuModels.reload() rootModule.controllersModule.adminPrivateController.updateChunks() + rootModule.tempFileManager.reload() rootModule.autoBroadcastJob.value.apply { this.onDisable() this.onEnable() diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/RootModule.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/RootModule.kt index cb07b56..66032f5 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/RootModule.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/RootModule.kt @@ -40,4 +40,5 @@ interface RootModule : Module { val commandsModule: CommandsModule val adminPrivateModule: AdminPrivateControllerModule val economyProvider: Single + val tempFileManager: Reloadable } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RoleControllerModuleImpl.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RoleControllerModuleImpl.kt index ae7126e..a13000f 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RoleControllerModuleImpl.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RoleControllerModuleImpl.kt @@ -3,6 +3,9 @@ package ru.astrainteractive.aspekt.di.impl import ru.astrainteractive.aspekt.di.RootModule import ru.astrainteractive.aspekt.event.discord.controllers.di.RoleControllerModule import ru.astrainteractive.aspekt.plugin.PluginConfiguration +import ru.astrainteractive.aspekt.plugin.PluginTranslation +import ru.astrainteractive.astralibs.economy.EconomyProvider +import ru.astrainteractive.astralibs.filemanager.SpigotFileManager import ru.astrainteractive.astralibs.logging.Logger import ru.astrainteractive.klibs.kdi.getValue @@ -11,4 +14,7 @@ class RoleControllerModuleImpl( ) : RoleControllerModule { override val pluginConfiguration: PluginConfiguration by rootModule.pluginConfig override val logger: Logger by rootModule.logger + override val economyProvider: EconomyProvider? by rootModule.economyProvider + override val tempFileManager: SpigotFileManager by rootModule.tempFileManager + override val translation: PluginTranslation by rootModule.translation } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RootModuleImpl.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RootModuleImpl.kt index 536e0eb..ad2ab8b 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RootModuleImpl.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/di/impl/RootModuleImpl.kt @@ -20,6 +20,7 @@ import ru.astrainteractive.astralibs.economy.EconomyProvider import ru.astrainteractive.astralibs.events.EventListener import ru.astrainteractive.astralibs.filemanager.DefaultSpigotFileManager import ru.astrainteractive.astralibs.filemanager.FileManager +import ru.astrainteractive.astralibs.filemanager.SpigotFileManager import ru.astrainteractive.astralibs.filemanager.impl.JVMFileManager import ru.astrainteractive.astralibs.logging.JUtilLogger import ru.astrainteractive.astralibs.logging.Logger @@ -97,6 +98,9 @@ object RootModuleImpl : RootModule { EconomyProviderFactory().create() }.onFailure { it.printStackTrace() }.getOrNull() } + override val tempFileManager: Reloadable = Reloadable { + DefaultSpigotFileManager(plugin.value, "temp.yml") + } // etc override val discordEvent = Single { diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/DiscordController.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/DiscordController.kt index bf8d39f..1bfb15d 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/DiscordController.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/DiscordController.kt @@ -5,8 +5,11 @@ import github.scarsz.discordsrv.api.events.AccountUnlinkedEvent import github.scarsz.discordsrv.dependencies.jda.api.JDA import github.scarsz.discordsrv.dependencies.jda.api.entities.Role import github.scarsz.discordsrv.util.DiscordUtil +import org.bukkit.Bukkit import ru.astrainteractive.aspekt.event.discord.controllers.di.RoleControllerModule import ru.astrainteractive.aspekt.plugin.PluginConfiguration +import ru.astrainteractive.astralibs.utils.uuid +import java.util.UUID @Suppress("DuplicatedCode") class DiscordController(module: RoleControllerModule) : RoleController, RoleControllerModule by module { @@ -17,7 +20,26 @@ class DiscordController(module: RoleControllerModule) : RoleController, RoleCont private suspend fun mapRoles(jda: JDA, list: List): List = list.mapNotNull { jda.getRoleById(it) } + private fun tryAddMoney(uuid: UUID) { + val player = Bukkit.getPlayer(uuid) ?: return + val key = "discord.linked.was_before.${player.uuid}" + val wasLinkedBefore = tempFileManager.fileConfiguration.getBoolean(key, false) + if (wasLinkedBefore) { + logger.info("DiscordEvent", "Игрок ${player.name} уже линковал аккаунт, пропускаем выдачу денег") + return + } + logger.info( + "DiscordEvent", + "Игроку ${player.name} выдано ${configuration.moneyForLink} за линковку с дискордом" + ) + tempFileManager.fileConfiguration.set(key, true) + tempFileManager.save() + economyProvider?.addMoney(uuid, configuration.moneyForLink.toDouble()) + player.sendMessage(translation.discordLinkReward(configuration.moneyForLink)) + } + override suspend fun onLinked(e: AccountLinkedEvent) { + tryAddMoney(e.player.uniqueId) logger.info("DiscordEvent", "Игрок ${e.player.name} линкует аккаунт") val member = e.user?.id?.let(DiscordUtil::getMemberById) ?: run { logger.info("DiscordEvent", "Игрок ${e.player.name} не на нашем сервере") diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/di/RoleControllerModule.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/di/RoleControllerModule.kt index ec50b83..e6707c1 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/di/RoleControllerModule.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/discord/controllers/di/RoleControllerModule.kt @@ -1,9 +1,15 @@ package ru.astrainteractive.aspekt.event.discord.controllers.di import ru.astrainteractive.aspekt.plugin.PluginConfiguration +import ru.astrainteractive.aspekt.plugin.PluginTranslation +import ru.astrainteractive.astralibs.economy.EconomyProvider +import ru.astrainteractive.astralibs.filemanager.SpigotFileManager import ru.astrainteractive.astralibs.logging.Logger interface RoleControllerModule { val pluginConfiguration: PluginConfiguration val logger: Logger + val economyProvider: EconomyProvider? + val tempFileManager: SpigotFileManager + val translation: PluginTranslation } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/sort/SortController.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/sort/SortController.kt index 5525081..44ee6b7 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/sort/SortController.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/event/sort/SortController.kt @@ -22,7 +22,6 @@ class SortController { val contents = clickedInventory.storageContents val sortType = sortTypes[player.uniqueId]?.next(Sort.values()) ?: Sort.values().first() sortTypes[player.uniqueId] = sortType - println(sortType) clickedInventory.storageContents = when (sortType) { Sort.TYPE_ASC -> sortByType(contents, sortType.desc) Sort.TYPE_DESC -> sortByType(contents, sortType.desc) diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt index ffd1aba..c6634b8 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt @@ -57,6 +57,7 @@ class PluginConfiguration(private val fc: FileConfiguration) { } inner class DiscordSRVLink { + val moneyForLink by fc.cInt("discordsrv.on_linked.add_money", 0) val discordOnLinked = Roles("on_linked.discord") val luckPermsOnLinked = Roles("on_linked.luckperms") val discordOnUnLinked = Roles("on_unlinked.discord") diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt index 09c62a8..c81ad7e 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginTranslation.kt @@ -29,6 +29,11 @@ class PluginTranslation(plugin: Plugin) : BaseTranslation() { val wrongUsage = translationValue("general.wrong_usage", "#db2c18Неверное использование!") val onlyPlayerCommand = translationValue("general.only_player_command", "#db2c18Эта команда только для игроков!") val menuNotFound = translationValue("general.menu_not_found", "#db2c18Меню с заданным ID не найдено") + private val discordLinkReward = translationValue( + "general.discord_link_reward", + "#42f596Вы получили {AMOUNT}$ за привязку дискорда!" + ) + fun discordLinkReward(amount: Number) = discordLinkReward.replace("{AMOUNT}", "${amount.toInt()}") // Admin claim val chunkFlagChanged = translationValue("general.adminprivate.flag_changed", "#db2c18Флаг чанка изменен!") diff --git a/plugin/src/main/resources/temp.yml b/plugin/src/main/resources/temp.yml new file mode 100644 index 0000000..e69de29