From 7a5f28159438f56e8cf530f0188c32f440a399bb Mon Sep 17 00:00:00 2001 From: Boy0000 Date: Tue, 20 Jun 2023 19:42:42 +0200 Subject: [PATCH] 1.20 (#50) --- .github/workflows/build.yml | 24 +++ .github/workflows/gradle-ci.yml | 37 ---- .github/workflows/publish-packages.yml | 49 ----- .github/workflows/publish.yml | 42 ++++ build.gradle.kts | 15 +- chatty-paper/build.gradle.kts | 36 +++- .../com/mineinabyss/chatty/ChattyCommands.kt | 183 +++++++----------- .../com/mineinabyss/chatty/ChattyConfig.kt | 174 ++++++++--------- .../com/mineinabyss/chatty/ChattyContext.kt | 14 +- .../com/mineinabyss/chatty/ChattyMessages.kt | 147 +++++++------- .../com/mineinabyss/chatty/ChattyPlugin.kt | 70 ++++--- .../chatty/components/ChannelData.kt | 26 ++- .../chatty/components/ChattyNickname.kt | 6 +- .../mineinabyss/chatty/helpers/ChatHelpers.kt | 60 +++--- .../chatty/helpers/DiscordEmoteFixer.kt | 8 +- .../chatty/helpers/NicknameHelpers.kt | 9 +- .../chatty/helpers/PluginHelpers.kt | 11 +- .../chatty/listeners/ChatListener.kt | 25 ++- .../chatty/listeners/ChattyProxyListener.kt | 76 ++++---- .../chatty/listeners/DiscordListener.kt | 47 ++--- .../chatty/listeners/PlayerListener.kt | 22 ++- .../chatty/placeholders/PlaceholderAPIHook.kt | 4 +- .../chatty/placeholders/Placeholders.kt | 21 +- .../com/mineinabyss/chatty/tags/ChattyTags.kt | 2 +- chatty-paper/src/main/resources/plugin.yml | 4 +- chatty-velocity/build.gradle.kts | 29 +-- gradle.properties | 8 +- gradle/chattyLibs.versions.toml | 10 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 31 ++- 30 files changed, 556 insertions(+), 636 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/gradle-ci.yml delete mode 100644 .github/workflows/publish-packages.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2c745d6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Java CI with Gradle + +on: + pull_request: + +concurrency: + cancel-in-progress: true + group: ci-${{ github.ref }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + cache: gradle + + - name: Run build + run: gradle build diff --git a/.github/workflows/gradle-ci.yml b/.github/workflows/gradle-ci.yml deleted file mode 100644 index 6eba9c9..0000000 --- a/.github/workflows/gradle-ci.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Java CI with Gradle - -on: - push: - branches: - - master - - backport_master - paths-ignore: - - '**.md' - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 17 - - - name: Build - run: gradle build - - - name: Upload Velocity build - uses: actions/upload-artifact@v1 - with: - name: velocity-build - path: chatty-velocity/build/libs - - - name: Upload Paper build - uses: actions/upload-artifact@v1 - with: - name: paper-build - path: chatty-paper/build/libs diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml deleted file mode 100644 index 2ac2b35..0000000 --- a/.github/workflows/publish-packages.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Publish GitHub Packages - -on: - push: - branches: - - master - - backport_master - paths-ignore: - - '**.md' - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 17 - - - name: Set env variable from latest maven version - run: > - echo "RELEASE_VERSION=$( \ - curl https://repo.mineinabyss.com/releases/com/mineinabyss/chatty-paper/maven-metadata.xml | \ - grep -oP '(?!)[\d\.]*(?=)' \ - )" >> $GITHUB_ENV - - - name: Run gradle build and publish - run: gradle build publish -PmineinabyssMavenUsername=${{ secrets.MAVEN_PUBLISH_USERNAME }} -PmineinabyssMavenPassword=${{ secrets.MAVEN_PUBLISH_PASSWORD }} - - - name: Get version from gradle - shell: bash - id: extract_version - run: | - version=`gradle properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}'` - echo "::set-output name=version::$version" - - - name: Create GitHub Release - uses: marvinpinto/action-automatic-releases@latest - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false - automatic_release_tag: v${{ steps.extract_version.outputs.version }} - files: | - chatty-paper/build/libs/*-all.jar - chatty-velocity/build/libs/*-all.jar diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cb9d28b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +name: Publish Packages + +on: + push: + branches: + - master + - develop + paths-ignore: + - '**.md' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: MineInAbyss/publish-action@master + with: + maven-metadata-url: https://repo.mineinabyss.com/releases/com/mineinabyss/chatty/maven-metadata.xml + pages-path: build/dokka/htmlMultiModule/ + dokka: dokkaHtmlMultiModule + maven-username: ${{ secrets.MAVEN_PUBLISH_USERNAME }} + maven-password: ${{ secrets.MAVEN_PUBLISH_PASSWORD }} + release-files: | + ${{ github.workspace }}/publish/*.jar + ${{ github.workspace }}/chatty-velocity/build/publish/*.jar + + deploy: + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + if: ${{ github.ref == 'refs/heads/master' }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 diff --git a/build.gradle.kts b/build.gradle.kts index 495ce0c..d4b4c7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,11 @@ +@Suppress("DSL_SCOPE_VIOLATION") plugins { - kotlin("jvm") - kotlin("plugin.serialization") - id("com.mineinabyss.conventions.kotlin") - id("com.mineinabyss.conventions.papermc") - id("com.mineinabyss.conventions.publication") - id("com.mineinabyss.conventions.testing") - //id("com.mineinabyss.conventions.autoversion") + alias(libs.plugins.mia.kotlin.jvm) + alias(libs.plugins.kotlinx.serialization) + alias(libs.plugins.mia.papermc) + alias(libs.plugins.mia.testing) + alias(libs.plugins.mia.publication) + alias(libs.plugins.mia.autoversion) } dependencies { @@ -14,5 +14,4 @@ dependencies { compileOnly(libs.kotlinx.serialization.kaml) compileOnly(libs.kotlinx.coroutines) compileOnly(libs.minecraft.mccoroutine) - compileOnly(libs.koin.core) } diff --git a/chatty-paper/build.gradle.kts b/chatty-paper/build.gradle.kts index 371cad1..6207635 100644 --- a/chatty-paper/build.gradle.kts +++ b/chatty-paper/build.gradle.kts @@ -1,14 +1,16 @@ +@Suppress("DSL_SCOPE_VIOLATION") plugins { - id("com.mineinabyss.conventions.kotlin") - id("com.mineinabyss.conventions.papermc") - id("com.mineinabyss.conventions.copyjar") - id("com.mineinabyss.conventions.publication") - id("com.mineinabyss.conventions.testing") - //id("com.mineinabyss.conventions.autoversion") - kotlin("plugin.serialization") + alias(libs.plugins.mia.kotlin.jvm) + alias(libs.plugins.mia.papermc) + alias(libs.plugins.mia.testing) + alias(libs.plugins.mia.publication) + id(libs.plugins.mia.copyjar.get().pluginId) + alias(libs.plugins.kotlinx.serialization) } repositories { + mavenCentral() + maven("https://repo.mineinabyss.com/snapshots") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") maven("https://nexus.scarsz.me/content/groups/public/") // DiscordSRV maven("https://m2.dv8tion.net/releases") // DiscordSRV @@ -20,10 +22,9 @@ dependencies { compileOnly(libs.kotlinx.serialization.kaml) compileOnly(libs.kotlinx.coroutines) compileOnly(libs.minecraft.mccoroutine) - compileOnly(libs.koin.core) // Other plugins - compileOnly(chattyLibs.geary.papermc.core) + compileOnly(chattyLibs.geary.papermc) /// Third-party plugins compileOnly(chattyLibs.placeholderapi) @@ -31,5 +32,20 @@ dependencies { // Shaded implementation(chattyLibs.imageloader) - implementation(libs.idofront.core) + implementation(libs.bundles.idofront.core) + +} + +configurations { + findByName("runtimeClasspath")?.apply { + exclude(group = "org.jetbrains.kotlin") + } +} + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf( + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", + ) + } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt index 5bca695..03ccca8 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt @@ -6,15 +6,15 @@ import com.github.shynixn.mccoroutine.bukkit.asyncDispatcher import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.chatty.components.* import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.geary.papermc.access.toGeary -import com.mineinabyss.idofront.commands.arguments.optionArg +import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.idofront.commands.arguments.stringArg import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor import com.mineinabyss.idofront.commands.extensions.actions.ensureSenderIsPlayer import com.mineinabyss.idofront.commands.extensions.actions.playerAction +import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.events.call -import com.mineinabyss.idofront.messaging.miniMsg -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.idofront.textcomponents.miniMsg +import com.mineinabyss.idofront.textcomponents.serialize import io.papermc.paper.event.player.AsyncChatDecorateEvent import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -28,40 +28,12 @@ import kotlin.collections.component2 import kotlin.collections.set class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { - override val commands = commands(chatty) { + override val commands = commands(chatty.plugin) { "chatty"(desc = "Chatty commands") { "reload" { - val option by optionArg(listOf("all", "config", "messages", "emotefixer")) { default = "all" } action { - when (option) { - "all" -> { - ChattyConfig.reload() - ChattyMessages.reload() - DiscordEmoteFixer.reload() - chattyConfig = ChattyConfig.data - chattyMessages = ChattyMessages.data - emoteFixer = DiscordEmoteFixer.data - sender.sendConsoleMessage("Reloaded everything!") - } - - "config" -> { - ChattyConfig.reload() - chattyConfig = ChattyConfig.data - sender.sendConsoleMessage("Reloaded configs!") - } - - "messages" -> { - ChattyMessages.reload() - chattyMessages = ChattyMessages.data - sender.sendConsoleMessage("Reloaded messages!") - } - - "emotefixer" -> { - DiscordEmoteFixer.reload() - emoteFixer = DiscordEmoteFixer.data - sender.sendConsoleMessage("Reloaded emotefixer!") - } - } + chatty.plugin.createChattyContext() + sender.sendConsoleMessage("Chatty has been reloaded!") } // chatty.config.reload() is a thing but does not regen or remove stuff so // chatty.config.reload() @@ -83,8 +55,8 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { ensureSenderIsPlayer() action { val player = sender as? Player ?: return@action - player.chattyData.lastMessager?.let { player.handleSendingPrivateMessage(it, arguments, true) } - ?: player.sendFormattedMessage(chattyMessages.privateMessages.emptyReply) + player.chattyData.lastMessager?.toPlayer()?.let { player.handleSendingPrivateMessage(it, arguments, true) } + ?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply) } } "ping"(desc = "Commands related to the chat-ping feature.") { @@ -92,8 +64,8 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { ensureSenderIsPlayer() action { val player = sender as? Player ?: return@action - player.chattyData.disablePingSound = !player.chattyData.disablePingSound - player.sendFormattedMessage(chattyMessages.ping.toggledPingSound) + player.toGeary().setPersisting(player.chattyData.apply { ChannelData(channelId, lastChannelUsed, !disablePingSound, pingSound, lastMessager) }) + player.sendFormattedMessage(chatty.messages.ping.toggledPingSound) } } "sound"(desc = "Change your pingsound") { @@ -102,23 +74,21 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { action { val player = sender as? Player ?: return@action if (soundName in getAlternativePingSounds) { - player.chattyData.pingSound = soundName - player.sendFormattedMessage(chattyMessages.ping.changedPingSound) - } else { - player.sendFormattedMessage(chattyMessages.ping.invalidPingSound) - } + player.toGeary().setPersisting(player.chattyData.apply { ChannelData(channelId, lastChannelUsed, !disablePingSound, soundName, lastMessager) }) + player.sendFormattedMessage(chatty.messages.ping.changedPingSound) + } else player.sendFormattedMessage(chatty.messages.ping.invalidPingSound) } } } ("channels" / "ch")(desc = "List all channels") { action { - (sender as? Player)?.sendFormattedMessage(chattyMessages.channels.availableChannels) - ?: sender.sendMessage(chattyMessages.channels.availableChannels) + (sender as? Player)?.sendFormattedMessage(chatty.messages.channels.availableChannels) + ?: sender.sendRichMessage(chatty.messages.channels.availableChannels) } } ("nickname" / "nick") { action { - val nickMessage = chattyMessages.nicknames + val nickMessage = chatty.messages.nicknames val nick = arguments.toSentence() val player = sender as? Player val bypassFormatPerm = player?.hasPermission(ChattyPermissions.NICKNAME_OTHERS) == true @@ -134,7 +104,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { ?: sender.sendConsoleMessage(nickMessage.consoleNicknameSelf) } - arguments.first().startsWith(chattyConfig.nicknames.nickNameOtherPrefix) -> { + arguments.first().startsWith(chatty.config.nicknames.nickNameOtherPrefix) -> { val otherPlayer = arguments.getPlayerToNick() val otherNick = nick.removePlayerToNickFromString() @@ -174,13 +144,14 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { } "commandspy" { playerAction { - val player = sender as? Player ?: return@playerAction - if (player.toGeary().has()) { - player.toGeary().remove() - player.sendFormattedMessage(chattyMessages.spying.commandSpyOff) - } else { - player.toGeary().getOrSetPersisting { CommandSpy() } - player.sendFormattedMessage(chattyMessages.spying.commandSpyOn) + (sender as? Player)?.toGeary()?.let { + if (it.has()) { + it.remove() + player.sendFormattedMessage(chatty.messages.spying.commandSpyOff) + } else { + it.getOrSetPersisting { CommandSpy() } + player.sendFormattedMessage(chatty.messages.spying.commandSpyOn) + } } } } @@ -192,23 +163,23 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { val spy = player.toGeary().getOrSetPersisting { SpyOnChannels() } when { - channel !in chattyConfig.channels.keys -> - player.sendFormattedMessage(chattyMessages.channels.noChannelWithName) + channel !in chatty.config.channels.keys -> + player.sendFormattedMessage(chatty.messages.channels.noChannelWithName) getChannelFromId(channel)?.channelType == ChannelType.GLOBAL -> - player.sendFormattedMessage(chattyMessages.spying.cannotSpyOnChannel) + player.sendFormattedMessage(chatty.messages.spying.cannotSpyOnChannel) !player.hasPermission(getChannelFromId(channel)?.permission.toString()) -> - player.sendFormattedMessage(chattyMessages.spying.cannotSpyOnChannel) + player.sendFormattedMessage(chatty.messages.spying.cannotSpyOnChannel) channel in spy.channels -> { - player.sendFormattedMessage(chattyMessages.spying.stopSpyingOnChannel) + player.sendFormattedMessage(chatty.messages.spying.stopSpyingOnChannel) spy.channels.remove(channel) } else -> { spy.channels.add(channel) - player.sendFormattedMessage(chattyMessages.spying.startSpyingOnChannel) + player.sendFormattedMessage(chatty.messages.spying.startSpyingOnChannel) } } } @@ -222,7 +193,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { } } } - chattyConfig.channels.forEach { (channelId, channel) -> + chatty.config.channels.forEach { (channelId, channel) -> channel.channelAliases.forEach { alias -> alias { ensureSenderIsPlayer() @@ -263,8 +234,8 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { ensureSenderIsPlayer() action { val player = sender as? Player ?: return@action - player.chattyData.lastMessager?.let { player.handleSendingPrivateMessage(it, arguments, true) } - ?: player.sendFormattedMessage(chattyMessages.privateMessages.emptyReply) + player.chattyData.lastMessager?.toPlayer()?.let { player.handleSendingPrivateMessage(it, arguments, true) } + ?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply) } } } @@ -276,114 +247,90 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { args: Array ): List { val onlinePlayers = Bukkit.getOnlinePlayers().map { it.name } - val otherPrefix = chattyConfig.nicknames.nickNameOtherPrefix + val otherPrefix = chatty.config.nicknames.nickNameOtherPrefix return if (command.name == "chatty") { when (args.size) { - 1 -> listOf( - "message", - "ping", - "reload", - "channels", - "nickname", - "spy", - "commandspy" - ).filter { s -> s.startsWith(args[0]) } - + 1 -> listOf("message", "ping", "reload", "channels", "nickname", "spy", "commandspy").filter { s -> s.startsWith(args[0]) } 2 -> when (args[0]) { "ping" -> listOf("toggle", "sound").filter { s -> s.startsWith(args[1]) } "message", "msg" -> onlinePlayers.filter { s -> s.startsWith(args[1], true) } "spy" -> - chattyConfig.channels.keys.toList().filter { s -> - s.startsWith( - args[1], - true - ) && getChannelFromId(s)?.channelType != ChannelType.GLOBAL + chatty.config.channels.keys.toList().filter { s -> + s.startsWith(args[1], true) && getChannelFromId(s)?.channelType != ChannelType.GLOBAL } - - "reload", "rl" -> listOf( - "all", - "config", - "messages", - "emotefixer" - ).filter { s -> s.startsWith(args[1]) } - else -> emptyList() } - 3 -> when { args[1] == "sound" -> getAlternativePingSounds.filter { s -> s.startsWith(args[2], true) } args[1].startsWith(otherPrefix) -> onlinePlayers.filter { s -> s.replace(otherPrefix.toString(), "").startsWith(args[2], true) } - else -> emptyList() } - else -> emptyList() } } else emptyList() } private fun Player.shortcutCommand( - channel: Map.Entry?, + channel: Map.Entry?, arguments: List ) { val currentChannel = chattyData.channelId when { - channel == null -> sendFormattedMessage(chattyMessages.channels.noChannelWithName) + channel == null -> sendFormattedMessage(chatty.messages.channels.noChannelWithName) channel.value.permission.isNotBlank() && !hasPermission(channel.value.permission) -> - sendFormattedMessage(chattyMessages.channels.missingChannelPermission) + sendFormattedMessage(chatty.messages.channels.missingChannelPermission) arguments.isEmpty() -> swapChannelCommand(channel.key) else -> { - chattyData.channelId = channel.key - chattyData.lastChannelUsed = channel.key - chatty.launch(chatty.asyncDispatcher) { + toGeary().setPersisting(chattyData.copy(channelId = channel.key, lastChannelUsed = channel.key)) + chatty.plugin.launch(chatty.plugin.asyncDispatcher) { GenericChattyDecorateEvent(this@shortcutCommand, arguments.toSentence().miniMsg()).call { GenericChattyChatEvent(this@shortcutCommand, (this as AsyncChatDecorateEvent).result()).callEvent() } } - chattyData.channelId = currentChannel + toGeary().setPersisting(chattyData.copy(channelId = currentChannel)) } } } private val replyMap = mutableMapOf() - private fun Player.handleReplyTimer(): Job { - if (this in replyMap) return replyMap[this]!! - replyMap[this]?.cancel() - return chatty.launch(chatty.asyncDispatcher) { - delay(chattyConfig.privateMessages.messageReplyTime) - replyMap[this@handleReplyTimer]?.cancel() - replyMap.remove(this@handleReplyTimer) - this@handleReplyTimer.chattyData.lastMessager = null + private fun handleReplyTimer(player: Player): Job { + if (player in replyMap) return replyMap[player]!! + replyMap[player]?.cancel() + return chatty.plugin.launch(chatty.plugin.asyncDispatcher) { + delay(chatty.config.privateMessages.messageReplyTime) + replyMap[player]?.cancel() + replyMap.remove(player) + player.toGeary().setPersisting(player.chattyData.copy(lastMessager = null)) } } private fun Player.handleSendingPrivateMessage(player: Player, arguments: List, isReply: Boolean = false) { when { - !chattyConfig.privateMessages.enabled -> - sendFormattedMessage(chattyMessages.privateMessages.disabled) + !chatty.config.privateMessages.enabled -> + sendFormattedMessage(chatty.messages.privateMessages.disabled) isReply && this.chattyData.lastMessager == null -> - sendFormattedMessage(chattyMessages.privateMessages.emptyReply) + sendFormattedMessage(chatty.messages.privateMessages.emptyReply) !isReply && arguments.first().toPlayer() == null -> - sendFormattedMessage(chattyMessages.privateMessages.invalidPlayer) + sendFormattedMessage(chatty.messages.privateMessages.invalidPlayer) else -> { val msg = if (isReply) arguments.toSentence() else arguments.removeFirstArgumentOfStringList() if (msg.isEmpty() || this == player) return - replyMap[player] = player.handleReplyTimer() + replyMap[player] = handleReplyTimer(player) - this.sendFormattedPrivateMessage(chattyConfig.privateMessages.messageSendFormat, msg, player) - player.sendFormattedPrivateMessage(chattyConfig.privateMessages.messageReceiveFormat, msg, this) - player.chattyData.lastMessager = this - if (chattyConfig.privateMessages.messageSendSound.isNotEmpty()) - this.playSound(player.location, chattyConfig.privateMessages.messageSendSound, 1f, 1f) - if (chattyConfig.privateMessages.messageReceivedSound.isNotEmpty()) - player.playSound(player.location, chattyConfig.privateMessages.messageReceivedSound, 1f, 1f) + this.sendFormattedPrivateMessage(chatty.config.privateMessages.messageSendFormat, msg, player) + player.sendFormattedPrivateMessage(chatty.config.privateMessages.messageReceiveFormat, msg, this) + player.toGeary().setPersisting(player.chattyData.copy(lastMessager = uniqueId)) + if (chatty.config.privateMessages.messageSendSound.isNotEmpty()) + this.playSound(player.location, chatty.config.privateMessages.messageSendSound, 1f, 1f) + if (chatty.config.privateMessages.messageReceivedSound.isNotEmpty()) + player.playSound(player.location, chatty.config.privateMessages.messageReceivedSound, 1f, 1f) } } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt index b5a7974..4f55315 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt @@ -1,7 +1,6 @@ package com.mineinabyss.chatty import com.mineinabyss.chatty.components.ChannelType -import com.mineinabyss.idofront.config.IdofrontConfig import com.mineinabyss.idofront.serialization.DurationSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,101 +8,100 @@ import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.TextColor import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes -object ChattyConfig : IdofrontConfig(chatty, Data.serializer()) { - @Serializable - data class Data( - val playerHeadFont: String = "minecraft:chatty_heads", - val nicknames: Nickname = Nickname(), - val chat: Chat = Chat(), - val ping: Ping = Ping(), - val join: Join = Join(), - val leave: Leave = Leave(), - val proxy: Proxy = Proxy(), - val privateMessages: PrivateMessages = PrivateMessages(), - // Mutable so other plugins can add channels on their end - // Might be a safer way to do this but 3AM so first solution is the best solution - val channels: MutableMap = mutableMapOf("global" to ChattyChannel(ChannelType.GLOBAL)), - ) { - @Serializable - data class Chat( - val disableChatSigning: Boolean = true, - val commandSpyFormat: String = ": ", - ) +@Serializable +data class ChattyConfig( + val playerHeadFont: String = "minecraft:chatty_heads", + val nicknames: Nickname = Nickname(), + val chat: Chat = Chat(), + val ping: Ping = Ping(), + val join: Join = Join(), + val leave: Leave = Leave(), + val proxy: Proxy = Proxy(), + val privateMessages: PrivateMessages = PrivateMessages(), + // Mutable so other plugins can add channels on their end + // Might be a safer way to do this but 3AM so first solution is the best solution + val channels: MutableMap = mutableMapOf("global" to ChattyChannel(ChannelType.GLOBAL)), +) { - @Serializable - data class PrivateMessages( - val enabled: Boolean = true, - val proxy: Boolean = true, - val messageReplyTime: @Serializable(with = DurationSerializer::class) Duration = 5.minutes, - val messageSendFormat: String = "You -> : ", - val messageReceiveFormat: String = " -> You: ", - val messageSendSound: String = "", - val messageReceivedSound: String = "", - ) + @Serializable + data class Chat( + val disableChatSigning: Boolean = true, + val commandSpyFormat: String = ": ", + ) - @Serializable - data class Nickname( - val useDisplayName: Boolean = true, - val maxLength: Int = 32, - val countTagsInLength: Boolean = false, - val nickNameOtherPrefix: Char = '@', - ) + @Serializable + data class PrivateMessages( + val enabled: Boolean = true, + val proxy: Boolean = true, + val messageReplyTime: @Serializable(with = DurationSerializer::class) Duration = 5.minutes, + val messageSendFormat: String = "You -> : ", + val messageReceiveFormat: String = " -> You: ", + val messageSendSound: String = "", + val messageReceivedSound: String = "", + ) - @Serializable - data class Join( - val enabled: Boolean = true, - val firstJoin: FirstJoin = FirstJoin(), - ) + @Serializable + data class Nickname( + val useDisplayName: Boolean = true, + val maxLength: Int = 32, + val countTagsInLength: Boolean = false, + val nickNameOtherPrefix: Char = '@', + ) - @Serializable - data class FirstJoin( - val enabled: Boolean = true, - ) + @Serializable + data class Join( + val enabled: Boolean = true, + val firstJoin: FirstJoin = FirstJoin(), + ) - @Serializable - data class Leave( - val enabled: Boolean = true, - ) + @Serializable + data class FirstJoin( + val enabled: Boolean = true, + ) - @Serializable - data class Proxy( - val enableProxySwitchMessages: Boolean = true, - val discordSrvChannelID: String = "Global", - val sendProxyMessagesToDiscord: Boolean = true, - ) + @Serializable + data class Leave( + val enabled: Boolean = true, + ) - @Serializable - data class ChattyChannel( - val channelType: ChannelType, - val permission: String = "", - val logToConsole: Boolean = true, - val simpleConsoleMessages: Boolean = false, - val proxy: Boolean = false, - val discordsrv: Boolean = true, - val isDefaultChannel: Boolean = false, - val isStaffChannel: Boolean = false, - val format: String = "", - @SerialName("messageColor") val _messageColor: String = "white", - val channelRadius: Int = 0, - val channelAliases: List = listOf(), - ) { - val messageColor: TextColor - get() = TextColor.fromHexString(_messageColor) ?: NamedTextColor.NAMES.value(_messageColor) - ?: NamedTextColor.WHITE - } + @Serializable + data class Proxy( + val enableProxySwitchMessages: Boolean = true, + val discordSrvChannelID: String = "Global", + val sendProxyMessagesToDiscord: Boolean = true, + ) - @Serializable - data class Ping( - val enabledChannels: List = listOf(), - val defaultPingSound: String = "block.amethyst_block.place", - val alternativePingSounds: List = emptyList(), - val pingVolume: Float = 1.0f, - val pingPitch: Float = 1.0f, - val pingPrefix: String = "@", - val clickToReply: Boolean = true, - val pingReceiveFormat: String = "", - val pingSendFormat: String = "" - ) + @Serializable + data class ChattyChannel( + val channelType: ChannelType, + val permission: String = "", + val logToConsole: Boolean = true, + val simpleConsoleMessages: Boolean = false, + val proxy: Boolean = false, + val discordsrv: Boolean = true, + val isDefaultChannel: Boolean = false, + val isStaffChannel: Boolean = false, + val format: String = "", + @SerialName("messageColor") val _messageColor: String = "white", + val channelRadius: Int = 0, + val channelAliases: List = listOf(), + ) { + val messageColor: TextColor + get() = TextColor.fromHexString(_messageColor) ?: NamedTextColor.NAMES.value(_messageColor) + ?: NamedTextColor.WHITE } + + @Serializable + data class Ping( + val enabledChannels: List = listOf(), + val defaultPingSound: String = "block.amethyst_block.place", + val alternativePingSounds: List = emptyList(), + val pingVolume: Float = 1.0f, + val pingPitch: Float = 1.0f, + val pingPrefix: String = "@", + val clickToReply: Boolean = true, + val pingReceiveFormat: String = "", + val pingSendFormat: String = "" + ) } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt index e1a48fb..c8cda80 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt @@ -1,13 +1,17 @@ package com.mineinabyss.chatty +import com.mineinabyss.chatty.helpers.DiscordEmoteFixer +import com.mineinabyss.idofront.config.IdofrontConfig +import com.mineinabyss.idofront.di.DI import org.bukkit.Bukkit -val chatty: ChattyPlugin by lazy { Bukkit.getPluginManager().getPlugin("chatty") as ChattyPlugin } const val chattyProxyChannel = "chatty:proxy" -object ChattyContext { +val chatty by DI.observe() +interface ChattyContext { + val plugin: ChattyPlugin + val config: ChattyConfig + val messages: ChattyMessages + val emotefixer: DiscordEmoteFixer val isPlaceholderApiLoaded: Boolean - get() = chatty.server.pluginManager.isPluginEnabled("PlaceholderAPI") val isDiscordSRVLoaded: Boolean - get() = chatty.server.pluginManager.isPluginEnabled("DiscordSRV") - } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyMessages.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyMessages.kt index 285308b..21c6cd7 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyMessages.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyMessages.kt @@ -1,88 +1,85 @@ package com.mineinabyss.chatty -import com.mineinabyss.idofront.config.IdofrontConfig import kotlinx.serialization.Serializable -object ChattyMessages : IdofrontConfig(chatty, Data.serializer()) { - @Serializable - class Data( - val nicknames: Nicknames = Nicknames(), - val privateMessages: PrivateMessages = PrivateMessages(), - val spying: Spying = Spying(), - val ping: Pings = Pings(), - val channels: Channels = Channels(), - val proxies: Proxies = Proxies(), - val joinLeave: JoinLeave = JoinLeave(), - val other: Other = Other() - ) { +@Serializable +class ChattyMessages( + val nicknames: Nicknames = Nicknames(), + val privateMessages: PrivateMessages = PrivateMessages(), + val spying: Spying = Spying(), + val ping: Pings = Pings(), + val channels: Channels = Channels(), + val proxies: Proxies = Proxies(), + val joinLeave: JoinLeave = JoinLeave(), + val other: Other = Other() +) { - @Serializable - data class PrivateMessages( - val disabled: String = "Private messages are disabled", - val invalidPlayer: String = "This player is not online or does not exist", - val emptyReply: String = "You have noone to reply to" - ) + @Serializable + data class PrivateMessages( + val disabled: String = "Private messages are disabled", + val invalidPlayer: String = "This player is not online or does not exist", + val emptyReply: String = "You have noone to reply to" + ) - @Serializable - data class Spying( - val commandSpyOn: String = "You are now spying on commands", - val commandSpyOff: String = "You are no longer spying on commands", - val startSpyingOnChannel: String = "Started spying on ", - val stopSpyingOnChannel: String = "Stopped spying on ", - val cannotSpyOnChannel: String = "You cannot spy on ", - val noChannelWithName: String = "No channel by this name exists." - ) + @Serializable + data class Spying( + val commandSpyOn: String = "You are now spying on commands", + val commandSpyOff: String = "You are no longer spying on commands", + val startSpyingOnChannel: String = "Started spying on ", + val stopSpyingOnChannel: String = "Stopped spying on ", + val cannotSpyOnChannel: String = "You cannot spy on ", + val noChannelWithName: String = "No channel by this name exists." + ) - @Serializable - data class Nicknames( - val selfSuccess: String = "You changed your nickname to !", - val selfDenied: String = "You can't change your nickname!", - val selfEmpty: String = "Removed nickname!", - val otherSuccess: String = "You changed %player_name%'s nickname to !", - val otherDenied: String = "You can't change %player_name%'s nickname!", - val otherEmpty: String = "Removed nickname for %player_name%!", - val invalidPlayer: String = "That player doesn't exist!", - val consoleNicknameSelf: String = "Sadly console cannot have cool nickname :(", - val tooLong: String = "This nickname contains formatting that are not allowed!", - ) + @Serializable + data class Nicknames( + val selfSuccess: String = "You changed your nickname to !", + val selfDenied: String = "You can't change your nickname!", + val selfEmpty: String = "Removed nickname!", + val otherSuccess: String = "You changed %player_name%'s nickname to !", + val otherDenied: String = "You can't change %player_name%'s nickname!", + val otherEmpty: String = "Removed nickname for %player_name%!", + val invalidPlayer: String = "That player doesn't exist!", + val consoleNicknameSelf: String = "Sadly console cannot have cool nickname :(", + val tooLong: String = "This nickname contains formatting that are not allowed!", + ) - @Serializable - data class Pings( - val toggledPingSound: String = "Ping sound is now .", - val changedPingSound: String = "Ping sound set to ", - val invalidPingSound: String = "You must specify a valid sound to play.", - ) + @Serializable + data class Pings( + val toggledPingSound: String = "Ping sound is now .", + val changedPingSound: String = "Ping sound set to ", + val invalidPingSound: String = "You must specify a valid sound to play.", + ) - @Serializable - data class Channels( - val availableChannels: String = "Available channels are:", - val channelChanged: String = "You have changed to channel .", - val noChannelWithName: String = "No channel by this name exists.", - val missingChannelPermission: String = "You do not have permission to join this channel.", - val emptyChannelMessage: String = "There is no-one to read your message", - ) + @Serializable + data class Channels( + val availableChannels: String = "Available channels are:", + val channelChanged: String = "You have changed to channel .", + val noChannelWithName: String = "No channel by this name exists.", + val missingChannelPermission: String = "You do not have permission to join this channel.", + val emptyChannelMessage: String = "There is no-one to read your message", + ) - @Serializable - data class Proxies( - val proxyJoin: String = "+ | %player_server%)", - val proxyLeave: String = "- | ", - val proxySwitchToMessage: String = " left to server.", - val proxySwitchFromMessage: String = " left to server.", - ) + @Serializable + data class Proxies( + val proxyJoin: String = "+ | %player_server%)", + val proxyLeave: String = "- | ", + val proxySwitchToMessage: String = " left to server.", + val proxySwitchFromMessage: String = " left to server.", + ) - @Serializable - data class JoinLeave( - val firstJoinMessage: String = "Welcome %player_name% to %server_name%", - val joinMessage: String = "%player_name% has joined the server.", - val leaveMessage: String = "%player_name% has left the server.", - ) + @Serializable + data class JoinLeave( + val firstJoinMessage: String = "Welcome %player_name% to %server_name%", + val joinMessage: String = "%player_name% has joined the server.", + val leaveMessage: String = "%player_name% has left the server.", + ) - @Serializable - data class Other( - val disallowedStyling: String = "Your message contains formatting you cannot use!", - val configReloaded: String = "Chatty config reloaded.", - val messagesReloaded: String = "Chatty messages reloaded.", - val nickNameChanged: String = "Nickname set to .", - ) - } + @Serializable + data class Other( + val disallowedStyling: String = "Your message contains formatting you cannot use!", + val configReloaded: String = "Chatty config reloaded.", + val messagesReloaded: String = "Chatty messages reloaded.", + val nickNameChanged: String = "Nickname set to .", + ) } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt index a9bf4f2..eea59fc 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt @@ -1,61 +1,83 @@ package com.mineinabyss.chatty +import com.mineinabyss.chatty.helpers.DiscordEmoteFixer import com.mineinabyss.chatty.listeners.ChatListener import com.mineinabyss.chatty.listeners.ChattyProxyListener import com.mineinabyss.chatty.listeners.DiscordListener import com.mineinabyss.chatty.listeners.PlayerListener import com.mineinabyss.chatty.placeholders.PlaceholderAPIHook -import com.mineinabyss.geary.addon.autoscan -import com.mineinabyss.geary.papermc.dsl.gearyAddon -import com.mineinabyss.idofront.platforms.IdofrontPlatforms -import com.mineinabyss.idofront.plugin.registerEvents +import com.mineinabyss.geary.autoscan.autoscan +import com.mineinabyss.geary.modules.geary +import com.mineinabyss.idofront.config.config +import com.mineinabyss.idofront.di.DI +import com.mineinabyss.idofront.platforms.Platforms +import com.mineinabyss.idofront.plugin.listeners import github.scarsz.discordsrv.DiscordSRV +import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin class ChattyPlugin : JavaPlugin() { - override fun onLoad() { - IdofrontPlatforms.load(this, "mineinabyss") + Platforms.load(this, "mineinabyss") } override fun onEnable() { + createChattyContext() + saveDefaultAssets() - saveResource("config.yml", false) - saveResource("emotefixer.yml", false) - saveResource("messages.yml", false) // Register the proxy listener - try { - server.messenger.registerIncomingPluginChannel(this, chattyProxyChannel, ChattyProxyListener()) - server.messenger.registerOutgoingPluginChannel(this, chattyProxyChannel) - } catch (e: IllegalArgumentException) { - logger.warning("Could not register proxy channel. Is another plugin using it?") - } + registerProxyChannels() - if (ChattyContext.isPlaceholderApiLoaded) + ChattyCommands() + listeners(ChatListener(), PlayerListener()) + + if (chatty.isPlaceholderApiLoaded) PlaceholderAPIHook().register() - if (ChattyContext.isDiscordSRVLoaded) + if (chatty.isDiscordSRVLoaded) DiscordSRV.api.subscribe(DiscordListener()) - gearyAddon { - autoscan("com.mineinabyss") { + geary { + autoscan(classLoader, "com.mineinabyss.chatty") { all() } ChattyCommands() + listeners(ChatListener(), PlayerListener()) + } + } - registerEvents(ChatListener(), PlayerListener()) + fun createChattyContext() { + DI.remove() + val chattyContext = object : ChattyContext { + override val plugin: ChattyPlugin = this@ChattyPlugin + override val config: ChattyConfig by config("config") { fromPluginPath(loadDefault = true) } + override val messages: ChattyMessages by config("messages") { fromPluginPath(loadDefault = true) } + override val emotefixer: DiscordEmoteFixer by config("emotefixer") { fromPluginPath(loadDefault = true) } + override val isPlaceholderApiLoaded: Boolean = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") + override val isDiscordSRVLoaded: Boolean = Bukkit.getPluginManager().isPluginEnabled("DiscordSRV") } + + DI.add(chattyContext) } override fun onDisable() { - if (ChattyContext.isDiscordSRVLoaded) + if (chatty.isDiscordSRVLoaded) DiscordSRV.api.unsubscribe(DiscordListener()) } private fun saveDefaultAssets() { - chatty.saveResource("assets/minecraft/font/chatty_heads.json", true) - chatty.saveResource("assets/space/textures/ui/utils/null.png", true) - chatty.saveResource("assets/space/textures/ui/utils/whiteblank_4.png", true) + chatty.plugin.saveResource("assets/minecraft/font/chatty_heads.json", true) + chatty.plugin.saveResource("assets/space/textures/ui/utils/null.png", true) + chatty.plugin.saveResource("assets/space/textures/ui/utils/whiteblank_4.png", true) + } + + private fun registerProxyChannels() { + try { + server.messenger.registerIncomingPluginChannel(this, chattyProxyChannel, ChattyProxyListener()) + server.messenger.registerOutgoingPluginChannel(this, chattyProxyChannel) + } catch (e: IllegalArgumentException) { + logger.warning("Could not register proxy channel. Is another plugin using it?") + } } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt index 6e89f72..959eeba 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt @@ -1,28 +1,24 @@ package com.mineinabyss.chatty.components import com.mineinabyss.chatty.helpers.getDefaultChat -import com.mineinabyss.chatty.helpers.toPlayer -import com.mineinabyss.geary.papermc.access.toGeary +import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.serialization.UUIDSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.entity.Player +import java.util.* @Serializable @SerialName("chatty:chatty_data") -class ChannelData( - var channelId: String = getDefaultChat().key, - var lastChannelUsed: String = channelId, - var disablePingSound: Boolean = false, - var pingSound: String? = null, - @SerialName("lastMessager") - var _lastMessager: String? = null, -) { - var lastMessager - get() = _lastMessager?.toPlayer() - set(value) = run { _lastMessager = value?.name } -} +data class ChannelData( + val channelId: String = getDefaultChat().key, + val lastChannelUsed: String = channelId, + val disablePingSound: Boolean = false, + val pingSound: String? = null, + val lastMessager: @Serializable(UUIDSerializer::class) UUID? = null, +) -val Player.chattyData get() = toGeary().getOrSetPersisting { ChannelData() } +val Player.chattyData get() = toGeary().getOrSetPersisting { ChannelData() } enum class ChannelType { GLOBAL, RADIUS, diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChattyNickname.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChattyNickname.kt index b979ead..47ffad6 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChattyNickname.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChattyNickname.kt @@ -1,8 +1,8 @@ package com.mineinabyss.chatty.components -import com.mineinabyss.chatty.helpers.chattyConfig +import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.helpers.parseTags -import com.mineinabyss.geary.papermc.access.toGeary +import com.mineinabyss.geary.papermc.tracking.entities.toGeary import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.entity.Player @@ -13,6 +13,6 @@ data class ChattyNickname(val nickname: String) var Player.chattyNickname get() = this.toGeary().get()?.nickname set(value) = this.toGeary().run { - if (chattyConfig.nicknames.useDisplayName) this@chattyNickname.displayName(value?.parseTags(this@chattyNickname) ?: name()) + if (chatty.config.nicknames.useDisplayName) this@chattyNickname.displayName(value?.parseTags(this@chattyNickname) ?: name()) value?.let { setPersisting(ChattyNickname(it)) } ?: remove() } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt index f7ce7aa..660c651 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt @@ -3,12 +3,14 @@ package com.mineinabyss.chatty.helpers import com.combimagnetron.imageloader.Avatar import com.combimagnetron.imageloader.Image.ColorType import com.combimagnetron.imageloader.ImageUtils +import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.components.ChannelType import com.mineinabyss.chatty.components.chattyData import com.mineinabyss.chatty.components.chattyNickname import com.mineinabyss.chatty.placeholders.chattyPlaceholderTags -import com.mineinabyss.idofront.messaging.miniMsg -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.textcomponents.miniMsg +import com.mineinabyss.idofront.textcomponents.serialize import me.clip.placeholderapi.PlaceholderAPI import net.kyori.adventure.key.Key import net.kyori.adventure.text.Component @@ -21,9 +23,10 @@ import org.bukkit.Sound import org.bukkit.SoundCategory import org.bukkit.entity.Player import org.bukkit.profile.PlayerTextures.SkinModel +import java.util.regex.Pattern const val ZERO_WIDTH = "\u200B" -val ping = chattyConfig.ping +val ping = chatty.config.ping val getAlternativePingSounds: List = if ("*" in ping.alternativePingSounds || "all" in ping.alternativePingSounds) Sound.values().map { it.key.toString() }.toList() else ping.alternativePingSounds @@ -32,7 +35,7 @@ val getPingEnabledChannels: List = if ("*" in ping.enabledChannels || "all" in ping.enabledChannels) getAllChannelNames() else ping.enabledChannels fun String.checkForPlayerPings(channelId: String): Player? { - val ping = chattyConfig.ping + val ping = chatty.config.ping if (channelId !in getPingEnabledChannels || ping.pingPrefix.isEmpty() || ping.pingPrefix !in this) return null val pingedName = this.substringAfter(ping.pingPrefix).split(" ")[0] return Bukkit.getOnlinePlayers().firstOrNull { player -> @@ -44,7 +47,7 @@ fun String.checkForPlayerPings(channelId: String): Player? { fun Component.handlePlayerPings(player: Player, pingedPlayer: Player) { getChannelFromId(player.chattyData.channelId) ?: return - val ping = chattyConfig.ping + val ping = chatty.config.ping val pingSound = pingedPlayer.chattyData.pingSound ?: ping.defaultPingSound val clickToReply = if (ping.clickToReply) " { - val list = mutableListOf() - chattyConfig.channels.forEach { list.add(it.key) } - return list -} +fun getAllChannelNames() = chatty.config.channels.keys.toList() fun translatePlaceholders(player: Player, message: String): Component { return PlaceholderAPI.setPlaceholders(player, message).fixLegacy() @@ -133,7 +132,7 @@ fun translatePlaceholders(player: Player, message: String): Component { val playerHeadMapCache = mutableMapOf() fun OfflinePlayer.translatePlayerHeadComponent(): Component { - if (this !in playerHeadMapCache || playerHeadMapCache[this]!!.font() != Key.key(chattyConfig.playerHeadFont)) { + if (this !in playerHeadMapCache || playerHeadMapCache[this]!!.font() != Key.key(chatty.config.playerHeadFont)) { playerHeadMapCache[this] = runCatching { getPlayerHeadTexture(ascent = -5) }.getOrDefault(Component.empty()) } return playerHeadMapCache[this] ?: Component.empty() @@ -145,7 +144,7 @@ fun Player.refreshSkinInCaches() { playerHeadMapCache -= this } fun OfflinePlayer.translateFullPlayerSkinComponent(): Component { - if (this !in playerBodyMapCache || playerBodyMapCache[this]!!.font() != Key.key(chattyConfig.playerHeadFont)) { + if (this !in playerBodyMapCache || playerBodyMapCache[this]!!.font() != Key.key(chatty.config.playerHeadFont)) { playerBodyMapCache[this] = runCatching { getFullPlayerBodyTexture(ascent = -5) }.getOrDefault(Component.empty()) } return playerBodyMapCache[this] ?: Component.empty() @@ -155,7 +154,7 @@ fun OfflinePlayer.getPlayerHeadTexture( scale: Int = 1, ascent: Int = 0, colorType: ColorType = ColorType.MINIMESSAGE, - font: Key = Key.key(chattyConfig.playerHeadFont) + font: Key = Key.key(chatty.config.playerHeadFont) ): Component { val image = avatarBuilder(this, scale, ascent, colorType).getBodyBufferedImage(scale).getSubimage(4, 0, 8, 8) return "${ImageUtils.generateStringFromImage(image, colorType, ascent)}".miniMsg() @@ -165,7 +164,7 @@ fun OfflinePlayer.getFullPlayerBodyTexture( scale: Int = 1, ascent: Int = 0, colorType: ColorType = ColorType.MINIMESSAGE, - font: Key = Key.key(chattyConfig.playerHeadFont) + font: Key = Key.key(chatty.config.playerHeadFont) ): Component { val image = avatarBuilder(this, scale, ascent, colorType).getBodyBufferedImage(scale) return "${ImageUtils.generateStringFromImage(image, colorType, ascent)}".miniMsg() @@ -182,7 +181,9 @@ private fun avatarBuilder( .ascent(ascent).colorType(colorType).scale(scale).build() } -fun String.fixSerializedTags(): String = this.replace("\\<", "<").replace("\\>", ">") +fun String.fixSerializedTags(): String = this.replaceAll("\\\\(?!u)(?!\")", "") + +fun String.replaceAll(regex: String, replacement: String): String = Pattern.compile(regex).matcher(this).replaceAll(replacement) fun String.fixLegacy(): Component { return if ("§" in this) legacy.deserialize(this) @@ -197,15 +198,14 @@ fun Player.swapChannelCommand(channelId: String) { val newChannel = getChannelFromId(channelId) when { newChannel == null -> - sendFormattedMessage(chattyMessages.channels.noChannelWithName) + sendFormattedMessage(chatty.messages.channels.noChannelWithName) newChannel.permission.isNotBlank() && !hasPermission(newChannel.permission) -> - sendFormattedMessage(chattyMessages.channels.missingChannelPermission) + sendFormattedMessage(chatty.messages.channels.missingChannelPermission) else -> { - chattyData.channelId = channelId - chattyData.lastChannelUsed = channelId - sendFormattedMessage(chattyMessages.channels.channelChanged) + toGeary().setPersisting(chattyData.copy(channelId = channelId, lastChannelUsed = channelId)) + sendFormattedMessage(chatty.messages.channels.channelChanged) } } } @@ -221,3 +221,7 @@ fun formattedResult(player: Player, message: Component): Component { return parsedFormat.append(parsedMessage) } + +fun T.copyWithEdit(block: T.() -> T): T { + return block() +} diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/DiscordEmoteFixer.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/DiscordEmoteFixer.kt index 9cb932b..c5e7e08 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/DiscordEmoteFixer.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/DiscordEmoteFixer.kt @@ -1,10 +1,6 @@ package com.mineinabyss.chatty.helpers -import com.mineinabyss.chatty.chatty -import com.mineinabyss.idofront.config.IdofrontConfig import kotlinx.serialization.Serializable -object DiscordEmoteFixer : IdofrontConfig(chatty, Data.serializer()) { - @Serializable - data class Data(val emotes: Map = emptyMap()) -} +@Serializable +data class DiscordEmoteFixer(val emotes: Map = emptyMap()) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt index dd31fde..ed277ba 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt @@ -1,18 +1,19 @@ package com.mineinabyss.chatty.helpers +import com.mineinabyss.chatty.chatty import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.Bukkit import org.bukkit.entity.Player fun String.stripTags() = MiniMessage.miniMessage().stripTags(this) fun String.verifyNickLength(): Boolean { - return when (chattyConfig.nicknames.countTagsInLength) { - true -> this.length <= chattyConfig.nicknames.maxLength - false -> this.stripTags().length <= chattyConfig.nicknames.maxLength + return when (chatty.config.nicknames.countTagsInLength) { + true -> this.length <= chatty.config.nicknames.maxLength + false -> this.stripTags().length <= chatty.config.nicknames.maxLength } } fun List.getPlayerToNick(): Player? = Bukkit.getPlayer( - this.first().replace(chattyConfig.nicknames.nickNameOtherPrefix.toString(), "") + this.first().replace(chatty.config.nicknames.nickNameOtherPrefix.toString(), "") ) fun String.removePlayerToNickFromString(): String = diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt index c5e7f36..b5dbf8d 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt @@ -2,20 +2,17 @@ package com.mineinabyss.chatty.helpers -import com.mineinabyss.chatty.ChattyConfig -import com.mineinabyss.chatty.ChattyMessages +import com.mineinabyss.idofront.textcomponents.serialize import io.papermc.paper.chat.ChatRenderer import io.papermc.paper.event.player.AsyncChatDecorateEvent import io.papermc.paper.event.player.AsyncChatEvent +import net.kyori.adventure.chat.SignedMessage import net.kyori.adventure.text.Component import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import org.bukkit.entity.Player -var chattyConfig = ChattyConfig.data -var chattyMessages = ChattyMessages.data -var emoteFixer = DiscordEmoteFixer.data val legacy = LegacyComponentSerializer.builder().useUnusualXRepeatedCharacterHexFormat().build() fun GenericChattyDecorateEvent(player: Player, msg: Component) = - AsyncChatDecorateEvent(true, player, msg, true, formattedResult(player, msg)) + AsyncChatDecorateEvent(true, player, msg, formattedResult(player, msg)) fun GenericChattyChatEvent(player: Player, msg: Component) = - AsyncChatEvent(true, player, mutableSetOf(), ChatRenderer.defaultRenderer(), msg, msg) + AsyncChatEvent(true, player, mutableSetOf(), ChatRenderer.defaultRenderer(), msg, msg, SignedMessage.system(msg.serialize(), null)) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt index 99d4f40..a7e4ee7 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt @@ -5,9 +5,9 @@ import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.chattyProxyChannel import com.mineinabyss.chatty.components.* import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.geary.papermc.access.toGeary -import com.mineinabyss.idofront.messaging.miniMsg -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.textcomponents.miniMsg +import com.mineinabyss.idofront.textcomponents.serialize import io.papermc.paper.chat.ChatRenderer import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent import io.papermc.paper.event.player.AsyncChatDecorateEvent @@ -31,7 +31,7 @@ class ChatListener : Listener { @EventHandler fun PlayerCommandPreprocessEvent.onPlayerCommand() { Bukkit.getOnlinePlayers().filter { it != player && it.toGeary().has() }.forEach { p -> - p.sendFormattedMessage(chattyConfig.chat.commandSpyFormat, message, optionalPlayer = player) + p.sendFormattedMessage(chatty.config.chat.commandSpyFormat, message, optionalPlayer = player) } } @@ -65,7 +65,7 @@ class ChatListener : Listener { val proxyMessage = (("${player.name}$ZERO_WIDTH$channelId$ZERO_WIDTH" + MiniMessage.miniMessage().escapeTags(translatePlaceholders(player, channel.format).serialize()) + ZERO_WIDTH).miniMsg().append(message())).serialize().toByteArray() - player.sendPluginMessage(chatty, chattyProxyChannel, proxyMessage) + player.sendPluginMessage(chatty.plugin, chattyProxyChannel, proxyMessage) } val displayName = player.chattyNickname?.miniMsg() ?: player.displayName() @@ -80,14 +80,13 @@ class ChatListener : Listener { } if (pingedPlayer == null && viewers().isEmpty()) { - player.sendFormattedMessage(chattyMessages.channels.emptyChannelMessage) + player.sendFormattedMessage(chatty.messages.channels.emptyChannelMessage) viewers().clear() - } else if (chattyConfig.chat.disableChatSigning) { - viewers().forEach { a -> - RendererExtension.render(player, displayName, message(), a) - } + } else if (chatty.config.chat.disableChatSigning) { + viewers().filterIsInstance().forEach { it.sendMessage(message()) } viewers().clear() - } + isCancelled = true + } else renderer { _, _, _, _ -> return@renderer message() } } private fun setAudienceForChannelType(player: Player): Set { @@ -120,14 +119,14 @@ class ChatListener : Listener { private fun Player.sendFormattedMessage(vararg message: String, optionalPlayer: Player? = null) = this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message.joinToString(" ")).parseTags(optionalPlayer ?: this, true)) - private fun Component.stripMessageFormat(player: Player, channel: ChattyConfig.Data.ChattyChannel) = + private fun Component.stripMessageFormat(player: Player, channel: ChattyConfig.ChattyChannel) = plainText.serialize(this) .replace(plainText.serialize(translatePlaceholders(player, channel.format).parseTags(player, true)), "").miniMsg().parseTags(player, false) } object RendererExtension : ChatRenderer { override fun render(source: Player, sourceDisplayName: Component, message: Component, viewer: Audience): Component { - (viewer as? Player ?: Bukkit.getConsoleSender()).sendMessage(message) + return message } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt index 2a2e819..5753375 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt @@ -1,21 +1,24 @@ package com.mineinabyss.chatty.listeners -import com.mineinabyss.chatty.ChattyContext +import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.chattyProxyChannel import com.mineinabyss.chatty.components.ChannelType import com.mineinabyss.chatty.components.SpyOnChannels import com.mineinabyss.chatty.components.chattyData -import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.geary.papermc.access.toGeary -import com.mineinabyss.idofront.messaging.miniMsg +import com.mineinabyss.chatty.helpers.ZERO_WIDTH +import com.mineinabyss.chatty.helpers.getChannelFromId +import com.mineinabyss.chatty.helpers.getChannelFromPlayer +import com.mineinabyss.chatty.helpers.toPlayer +import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.textcomponents.miniMsg import github.scarsz.discordsrv.Debug import github.scarsz.discordsrv.DiscordSRV -import github.scarsz.discordsrv.dependencies.jda.api.Permission -import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed import github.scarsz.discordsrv.util.DiscordUtil import github.scarsz.discordsrv.util.MessageUtil import github.scarsz.discordsrv.util.PlaceholderUtil import github.scarsz.discordsrv.util.WebhookUtil +import net.dv8tion.jda.api.Permission +import net.dv8tion.jda.api.entities.MessageEmbed import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.plugin.messaging.PluginMessageListener @@ -52,57 +55,48 @@ class ChattyProxyListener : PluginMessageListener { } - if (!chattyConfig.proxy.sendProxyMessagesToDiscord || - channel?.discordsrv != true || !ChattyContext.isDiscordSRVLoaded + if (!chatty.config.proxy.sendProxyMessagesToDiscord || + channel?.discordsrv != true || !chatty.isDiscordSRVLoaded ) return - val dsrv = DiscordSRV.getPlugin() - var discordMessage = proxyMessage.replaceFirst(channelFormat, "") val reserializer = DiscordSRV.config().getBoolean("Experiment_MCDiscordReserializer_ToDiscord") - val discordChannel = - dsrv.getDestinationTextChannelForGameChannelName(chattyConfig.proxy.discordSrvChannelID) + val discordChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(chatty.config.proxy.discordSrvChannelID) - if (discordChannel == null) { - DiscordSRV.debug( - Debug.MINECRAFT_TO_DISCORD, - "Failed to find Discord channel to forward message from game channel $channel" - ) - } else if (!DiscordUtil.checkPermission(discordChannel.guild, Permission.MANAGE_WEBHOOKS)) { - DiscordSRV.error("Couldn't deliver chat message as webhook because the bot lacks the \"Manage Webhooks\" permission.") - } else { - discordMessage = PlaceholderUtil.replacePlaceholdersToDiscord(discordMessage) - if (!reserializer) discordMessage = MessageUtil.strip(discordMessage) + when { + discordChannel == null -> { + DiscordSRV.debug(Debug.MINECRAFT_TO_DISCORD, + "Failed to find Discord channel to forward message from game channel $channel") + } + !DiscordUtil.checkPermission(discordChannel.guild, Permission.MANAGE_WEBHOOKS) -> + DiscordSRV.error("Couldn't deliver chat message as webhook because the bot lacks the \"Manage Webhooks\" permission.") + else -> { + val discordMessage = proxyMessage.replaceFirst(channelFormat, "") + .apply { PlaceholderUtil.replacePlaceholdersToDiscord(this) } + .apply { if (!reserializer) MessageUtil.strip(this) } + .apply { if (translateMentions) DiscordUtil.convertMentionsFromNames(this, DiscordSRV.getPlugin().mainGuild) } - if (translateMentions) - discordMessage = DiscordUtil.convertMentionsFromNames(discordMessage, dsrv.mainGuild) - var whUsername: String = - DiscordSRV.config().getString("Experiment_WebhookChatMessageUsernameFormat") + val whUsername = DiscordSRV.config().getString("Experiment_WebhookChatMessageUsernameFormat") .replace("(%displayname%)|(%username%)".toRegex(), senderName) - whUsername = PlaceholderUtil.replacePlaceholders(whUsername) - whUsername = MessageUtil.strip(whUsername) + .let { MessageUtil.strip(PlaceholderUtil.replacePlaceholders(it)) } - WebhookUtil.deliverMessage( - discordChannel, - whUsername, - DiscordSRV.getAvatarUrl(senderName, senderName.toPlayer()?.uniqueId), - discordMessage.translateEmoteIDsToComponent(), - MessageEmbed(null, null, null, null, null, 10, null, null, null, null, null, null, null) - ) + WebhookUtil.deliverMessage(discordChannel, whUsername, + DiscordSRV.getAvatarUrl(senderName, senderName.toPlayer()?.uniqueId), + discordMessage.translateEmoteIDsToComponent(), + MessageEmbed(null, null, null, null, null, 10, null, null, null, null, null, null, null) + ) + } } } private val translateMentions = - if (!ChattyContext.isDiscordSRVLoaded) false else DiscordSRV.config().getBoolean("DiscordChatChannelTranslateMentions") + if (!chatty.isDiscordSRVLoaded) false else DiscordSRV.config().getBoolean("DiscordChatChannelTranslateMentions") private fun String.translateEmoteIDsToComponent(): String { var translated = this - emoteFixer.emotes.entries.forEach { (emoteId, replacement) -> + chatty.emotefixer.emotes.entries.forEach { (emoteId, replacement) -> val id = ":$emoteId:" if (id in translated) translated = translated.replace(id, "<$replacement") } - return translated.cleanUpHackyFix() + return translated.replace("<<", "<") } - - private fun String.cleanUpHackyFix() = - this.replace("<<", "<") } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/DiscordListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/DiscordListener.kt index 75efddf..37d5ec3 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/DiscordListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/DiscordListener.kt @@ -4,21 +4,24 @@ import com.mineinabyss.chatty.ChattyConfig import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.chattyProxyChannel import com.mineinabyss.chatty.components.chattyData -import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.chatty.helpers.getChannelFromId +import com.mineinabyss.chatty.helpers.getChannelFromPlayer +import com.mineinabyss.chatty.helpers.parseTags +import com.mineinabyss.chatty.helpers.translatePlaceholders +import com.mineinabyss.idofront.textcomponents.miniMsg +import com.mineinabyss.idofront.textcomponents.serialize import github.scarsz.discordsrv.api.ListenerPriority import github.scarsz.discordsrv.api.Subscribe import github.scarsz.discordsrv.api.events.* -import github.scarsz.discordsrv.dependencies.jda.api.MessageBuilder -import github.scarsz.discordsrv.dependencies.jda.api.entities.Message -import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed -import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed.Field -import github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component -import github.scarsz.discordsrv.dependencies.kyori.adventure.text.minimessage.MiniMessage -import github.scarsz.discordsrv.dependencies.kyori.adventure.text.minimessage.tag.resolver.TagResolver -import github.scarsz.discordsrv.dependencies.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer -import github.scarsz.discordsrv.dependencies.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import github.scarsz.discordsrv.objects.MessageFormat +import net.dv8tion.jda.api.MessageBuilder +import net.dv8tion.jda.api.entities.Message +import net.dv8tion.jda.api.entities.MessageEmbed +import net.dv8tion.jda.api.entities.MessageEmbed.Field +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.minimessage.MiniMessage +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import org.bukkit.Bukkit import org.bukkit.entity.Player @@ -32,8 +35,8 @@ class DiscordListener { @Subscribe(priority = ListenerPriority.HIGHEST) fun DiscordGuildMessagePostProcessEvent.sendDiscordToProxy() { minecraftMessage = (minecraftMessage.serialize() - .substringBefore(message.contentRaw) + mm.stripTags(message.contentStripped)).miniMessage() - Bukkit.getServer().sendPluginMessage(chatty, chattyProxyChannel, minecraftMessage.serialize().toByteArray()) + .substringBefore(message.contentRaw) + mm.stripTags(message.contentStripped)).miniMsg() + Bukkit.getServer().sendPluginMessage(chatty.plugin, chattyProxyChannel, minecraftMessage.serialize().toByteArray()) } @Subscribe(priority = ListenerPriority.NORMAL) @@ -49,8 +52,8 @@ class DiscordListener { } // Parse the DSRV Component through the Chatty normal MM instance to format tags, then serialize/deserialize it back to DSRV Component - fun Component.stripFormat(player: Player, channel: ChattyConfig.Data.ChattyChannel) = - plainText.serialize(this).replace(plainText.serialize(translatePlaceholders(player, channel.format).parseTags(player, true).serialize().miniMessage()), "").miniMessage() + private fun Component.stripFormat(player: Player, channel: ChattyConfig.ChattyChannel) = + plainText.serialize(this).replace(plainText.serialize(translatePlaceholders(player, channel.format).parseTags(player, true).serialize().miniMsg()), "").miniMsg() @Subscribe fun DeathMessagePreProcessEvent.onDeath() { @@ -72,8 +75,6 @@ class DiscordListener { discordMessage = discordMessage.translatePostFormat() } - fun String.fixSerializedTags(): String = this.replace("\\<", "<").replace("\\>", ">") - private fun Message.translatePostFormat(): Message { val message = this val embeds = mutableListOf() @@ -115,11 +116,11 @@ class DiscordListener { } private fun String.cleanUpHackyFix() = - plainText.serialize(this.miniMessage()).replace("\\<", "<").replace("<<", "<") + plainText.serialize(this.miniMsg()).replace("\\<", "<").replace("<<", "<") private fun String.translateEmoteIDs(): String { var translated = this - emoteFixer.emotes.entries.forEach { (emoteId, replacement) -> + chatty.emotefixer.emotes.entries.forEach { (emoteId, replacement) -> val id = ":$emoteId:" if (id in this) { translated = translated.replace(id, replacement) @@ -127,12 +128,4 @@ class DiscordListener { } return translated.cleanUpHackyFix() } - - private fun Component.serialize(): String { - return mm.serialize(this) - } - - private fun String.miniMessage(tagResolver: TagResolver = TagResolver.standard()): Component { - return mm.deserialize(this, tagResolver) - } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/PlayerListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/PlayerListener.kt index c12184b..658e986 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/PlayerListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/PlayerListener.kt @@ -1,10 +1,14 @@ package com.mineinabyss.chatty.listeners +import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.components.ChannelData import com.mineinabyss.chatty.components.HideJoinLeave -import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.geary.papermc.access.toGeary -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.chatty.helpers.parseTags +import com.mineinabyss.chatty.helpers.refreshSkinInCaches +import com.mineinabyss.chatty.helpers.translatePlaceholders +import com.mineinabyss.chatty.helpers.verifyPlayerChannel +import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.textcomponents.serialize import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener @@ -18,16 +22,16 @@ class PlayerListener : Listener { @EventHandler(priority = EventPriority.LOWEST) fun PlayerJoinEvent.onFirstJoin() { if (player.toGeary().has()) return - if (chattyConfig.join.enabled && chattyConfig.join.firstJoin.enabled) { - joinMessage(translatePlaceholders(player, chattyMessages.joinLeave.firstJoinMessage)) + if (chatty.config.join.enabled && chatty.config.join.firstJoin.enabled) { + joinMessage(translatePlaceholders(player, chatty.messages.joinLeave.firstJoinMessage)) } } @EventHandler(priority = EventPriority.NORMAL) fun PlayerJoinEvent.onJoin() { player.verifyPlayerChannel() - if (chattyConfig.join.enabled && !player.toGeary().has()) - joinMessage(translatePlaceholders(player, chattyMessages.joinLeave.joinMessage)) + if (chatty.config.join.enabled && !player.toGeary().has()) + joinMessage(translatePlaceholders(player, chatty.messages.joinLeave.joinMessage)) } @EventHandler @@ -35,8 +39,8 @@ class PlayerListener : Listener { // Remove player incase they switch skins player.refreshSkinInCaches() - if (chattyConfig.leave.enabled && !player.toGeary().has()) - quitMessage(translatePlaceholders(player, chattyMessages.joinLeave.leaveMessage)) + if (chatty.config.leave.enabled && !player.toGeary().has()) + quitMessage(translatePlaceholders(player, chatty.messages.joinLeave.leaveMessage)) } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/PlaceholderAPIHook.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/PlaceholderAPIHook.kt index 457c259..acdd7ee 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/PlaceholderAPIHook.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/PlaceholderAPIHook.kt @@ -7,8 +7,8 @@ import org.bukkit.entity.Player class PlaceholderAPIHook : PlaceholderExpansion() { override fun getIdentifier() = "chatty" - override fun getAuthor() = chatty.description.authors.toSentence() - override fun getVersion() = chatty.description.version + override fun getAuthor() = chatty.plugin.pluginMeta.authors.toSentence() + override fun getVersion() = chatty.plugin.pluginMeta.version override fun persist() = true override fun onPlaceholderRequest(player: Player, string: String): String { diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt index 51cb6db..cfae12e 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt @@ -1,13 +1,14 @@ package com.mineinabyss.chatty.placeholders +import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.components.SpyOnChannels import com.mineinabyss.chatty.components.chattyData import com.mineinabyss.chatty.components.chattyNickname import com.mineinabyss.chatty.helpers.* -import com.mineinabyss.geary.papermc.access.toGeary +import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.idofront.font.Space -import com.mineinabyss.idofront.messaging.miniMsg -import com.mineinabyss.idofront.messaging.serialize +import com.mineinabyss.idofront.textcomponents.miniMsg +import com.mineinabyss.idofront.textcomponents.serialize import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver import org.bukkit.entity.Player @@ -31,13 +32,13 @@ fun chattyPlaceholders(player: Player?, string: String? = null) : Map()?.channels?.lastOrNull().toString(), - "ping_defaultsound" to chattyConfig.ping.defaultPingSound, - "ping_volume" to chattyConfig.ping.pingVolume.toString(), - "ping_pitch" to chattyConfig.ping.pingPitch.toString(), - "ping_prefix" to chattyConfig.ping.pingPrefix, - "ping_clickreply" to chattyConfig.ping.clickToReply.toString(), - "ping_receiver_format" to chattyConfig.ping.pingReceiveFormat, - "ping_sender_format" to chattyConfig.ping.pingSendFormat, + "ping_defaultsound" to chatty.config.ping.defaultPingSound, + "ping_volume" to chatty.config.ping.pingVolume.toString(), + "ping_pitch" to chatty.config.ping.pingPitch.toString(), + "ping_prefix" to chatty.config.ping.pingPrefix, + "ping_clickreply" to chatty.config.ping.clickToReply.toString(), + "ping_receiver_format" to chatty.config.ping.pingReceiveFormat, + "ping_sender_format" to chatty.config.ping.pingSendFormat, "player_ping_sound" to player?.chattyData?.pingSound.toString(), "player_ping_toggle" to (player?.chattyData?.disablePingSound?.not() ?: "false").toString(), diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt index 9a4770c..ed5e28a 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt @@ -4,7 +4,7 @@ import com.mineinabyss.chatty.helpers.toPlayer import com.mineinabyss.chatty.helpers.translateFullPlayerSkinComponent import com.mineinabyss.chatty.helpers.translatePlayerHeadComponent import com.mineinabyss.idofront.font.Space -import com.mineinabyss.idofront.messaging.miniMsg +import com.mineinabyss.idofront.textcomponents.miniMsg import net.kyori.adventure.text.Component import net.kyori.adventure.text.minimessage.Context import net.kyori.adventure.text.minimessage.internal.serializer.SerializableResolver diff --git a/chatty-paper/src/main/resources/plugin.yml b/chatty-paper/src/main/resources/plugin.yml index 8a2e8cb..78adf51 100644 --- a/chatty-paper/src/main/resources/plugin.yml +++ b/chatty-paper/src/main/resources/plugin.yml @@ -1,8 +1,8 @@ -name: chatty +name: Chatty version: ${plugin_version} author: boy0000 main: com.mineinabyss.chatty.ChattyPlugin -api-version: 1.18 +api-version: "1.20" depend: [ Geary ] softdepend: [ BondrewdLikesHisEmotes, PlaceholderAPI, DiscordSRV ] description: Highly customizable chat plugin diff --git a/chatty-velocity/build.gradle.kts b/chatty-velocity/build.gradle.kts index 71141a0..e8f7462 100644 --- a/chatty-velocity/build.gradle.kts +++ b/chatty-velocity/build.gradle.kts @@ -7,8 +7,12 @@ plugins { kotlin("kapt") kotlin("plugin.serialization") id("com.github.johnrengelman.shadow") - //id("com.mineinabyss.conventions.autoversion") `maven-publish` + id(libs.plugins.mia.copyjar.get().pluginId) +} + +copyJar { + destPath.set(project.findProperty("velocity_plugin_path") as String? ?: "./build/publish") } repositories { @@ -27,26 +31,3 @@ dependencies { compileOnly(chattyLibs.velocity) kapt(chattyLibs.velocity) } - -tasks.build { - dependsOn(tasks.shadowJar.get()) -} - -val copyJar: String? by project -val pluginPath = project.findProperty("velocity_plugin_path") - -if(copyJar != "false" && pluginPath != null) { - tasks { - register("copyJar") { - from(findByName("reobfJar") ?: findByName("shadowJar") ?: findByName("jar")) - into(pluginPath) - doLast { - println("Copied to plugin directory $pluginPath") - } - } - - named("build") { - dependsOn("copyJar") - } - } -} diff --git a/gradle.properties b/gradle.properties index 4ec3ec8..999afd2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ group=com.mineinabyss -version=0.3 -kotlinVersion=1.6.10 -idofrontVersion=0.12.112 -serverVersion=1.19.2-R0.1-SNAPSHOT +version=0.6 +idofrontVersion=0.18.14 +velocityVersion=3.2.0 coroutinesVersion=1.6.4 -velocityVersion=3.1.1 diff --git a/gradle/chattyLibs.versions.toml b/gradle/chattyLibs.versions.toml index 26e753f..754eba4 100644 --- a/gradle/chattyLibs.versions.toml +++ b/gradle/chattyLibs.versions.toml @@ -1,11 +1,11 @@ [versions] -geary = "0.20.115" -velocity = "3.1.1" -discordsrv = "1.26.0" +geary = "0.24.1" +velocity = "3.2.0-SNAPSHOT" +discordsrv = "1.26.2" [libraries] -geary-papermc-core = { module = "com.mineinabyss:geary-papermc-core", version.ref = "geary" } +geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "geary" } velocity = { module = "com.velocitypowered:velocity-api", version.ref = "velocity" } discordsrv = { module = "com.discordsrv:discordsrv", version.ref = "discordsrv" } -placeholderapi = "me.clip:placeholderapi:2.11.2" +placeholderapi = "me.clip:placeholderapi:2.11.3" imageloader = "com.combimagnetron:imageloader:1.1-SNAPSHOT" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..fae0804 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 88e8fe6..e124cbe 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ +rootProject.name = "chatty" + pluginManagement { - val kotlinVersion: String by settings - val idofrontVersion: String by settings repositories { mavenCentral() @@ -10,25 +10,15 @@ pluginManagement { google() } - plugins { - - kotlin("jvm") version kotlinVersion - kotlin("kapt") version kotlinVersion - kotlin("plugin.serialization") version kotlinVersion - - id("com.github.johnrengelman.shadow") version "7.1.0" - } - - resolutionStrategy.eachPlugin { - if (requested.id.id.startsWith("com.mineinabyss.conventions")) useVersion(idofrontVersion) + val idofrontVersion: String by settings + resolutionStrategy { + eachPlugin { + if (requested.id.id.startsWith("com.mineinabyss.conventions")) + useVersion(idofrontVersion) + } } } -include( - "chatty-paper", - "chatty-velocity" -) - dependencyResolutionManagement { val idofrontVersion: String by settings @@ -42,4 +32,7 @@ dependencyResolutionManagement { } } -rootProject.name = "chatty" +include( + "chatty-paper", + "chatty-velocity" +)