diff --git a/chatty-paper/build.gradle.kts b/chatty-paper/build.gradle.kts index 0e55598..47a3186 100644 --- a/chatty-paper/build.gradle.kts +++ b/chatty-paper/build.gradle.kts @@ -29,9 +29,6 @@ dependencies { compileOnly(libs.placeholderapi) compileOnly(libs.discordsrv) - // Shaded - implementation(libs.imageloader) - } configurations { @@ -40,10 +37,12 @@ configurations { } } -tasks.withType { - kotlinOptions { - freeCompilerArgs = listOf( +kotlin { + compilerOptions { + freeCompilerArgs.addAll( "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-opt-in=kotlin.ExperimentalUnsignedTypes", + "-Xcontext-receivers" ) } } 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 5d89217..a9f7b2a 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt @@ -2,8 +2,6 @@ package com.mineinabyss.chatty import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.chatty.commands.ChattyBrigadierCommands -import com.mineinabyss.chatty.components.ChannelData -import com.mineinabyss.chatty.components.ChattyNickname import com.mineinabyss.chatty.helpers.DiscordEmoteFixer import com.mineinabyss.chatty.listeners.ChatListener import com.mineinabyss.chatty.listeners.ChattyProxyListener @@ -11,10 +9,10 @@ import com.mineinabyss.chatty.listeners.DiscordListener import com.mineinabyss.chatty.listeners.PlayerListener import com.mineinabyss.chatty.placeholders.PlaceholderAPIHook import com.mineinabyss.chatty.queries.SpyingPlayersQuery +import com.mineinabyss.geary.addons.dsl.createAddon import com.mineinabyss.geary.autoscan.autoscan -import com.mineinabyss.geary.helpers.componentId -import com.mineinabyss.geary.modules.geary -import com.mineinabyss.geary.systems.builders.cache +import com.mineinabyss.geary.papermc.configure +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.idofront.config.config import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.plugin.Plugins @@ -33,16 +31,21 @@ import net.kyori.adventure.chat.SignedMessage import org.bukkit.plugin.java.JavaPlugin class ChattyPlugin : JavaPlugin() { + + private val ChattyAddon = createAddon("Chatty", configuration = { + autoscan(classLoader, "com.mineinabyss.chatty") { + all() + } + }) + override fun onLoad() { - geary { - autoscan(classLoader, "com.mineinabyss.chatty") { - all() - } + gearyPaper.configure { + install(ChattyAddon) } // register components we'll use async now since they'll error otherwise - componentId() - componentId() + //componentId() + //componentId() } override fun onEnable() { @@ -74,7 +77,7 @@ class ChattyPlugin : JavaPlugin() { override val emotefixer: DiscordEmoteFixer by config("emotefixer", dataFolder.toPath(), DiscordEmoteFixer()) override val isPlaceholderApiLoaded: Boolean get() = Plugins.isEnabled("PlaceholderAPI") override val isDiscordSRVLoaded: Boolean get() = Plugins.isEnabled("DiscordSRV") - override val spyingPlayers = geary.cache(SpyingPlayersQuery()) + override val spyingPlayers = gearyPaper.worldManager.global.cache(::SpyingPlayersQuery) } DI.add(chattyContext) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/commands/ChattyBrigadierCommands.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/commands/ChattyBrigadierCommands.kt index 1a181b6..1bc7a05 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/commands/ChattyBrigadierCommands.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/commands/ChattyBrigadierCommands.kt @@ -16,6 +16,7 @@ import com.mineinabyss.geary.serialization.getOrSetPersisting import com.mineinabyss.geary.serialization.setPersisting import com.mineinabyss.idofront.commands.brigadier.IdoRootCommand import com.mineinabyss.idofront.commands.brigadier.commands +import com.mineinabyss.idofront.commands.brigadier.playerExecutes import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.events.call import com.mineinabyss.idofront.messaging.error @@ -71,36 +72,31 @@ object ChattyBrigadierCommands { } } "sound" { - playerExecutes { - player.error("Missing sound-argument...") - } - val soundName by StringArgumentType.word().suggests { + playerExecutes(StringArgumentType.word().suggests { suggest( chatty.config.ping.alternativePingSounds - .takeUnless { "all" in it } ?: Sound.entries.map { it.key.asString() } + .takeUnless { "all" in it } ?: Sound.entries.map { it.key().asString() } ) - } - playerExecutes { + }.named("sound")) { sound -> val gearyPlayer = player.toGeary() val oldData = gearyPlayer.get() ?: return@playerExecutes - if (soundName() in alternativePingSounds) { - gearyPlayer.setPersisting(oldData.copy(pingSound = soundName())) + if (sound in alternativePingSounds) { + gearyPlayer.setPersisting(oldData.copy(pingSound = sound)) player.sendFormattedMessage(chatty.messages.ping.changedPingSound) } else player.sendFormattedMessage(chatty.messages.ping.invalidPingSound) } } } "channels" { + requiresPermission("") executes { (sender as? Player)?.sendFormattedMessage(chatty.messages.channels.availableChannels) ?: sender.sendRichMessage(chatty.messages.channels.availableChannels) } } "channel" { - playerExecutes { - player.error("Missing channel-argument...") - } - val channel by ChattyChannelArgument().suggests { + requiresPermission("") + playerExecutes(ChattyChannelArgument().suggests { suggest(chatty.config.channels.entries.asSequence() .filter { it.value.channelType != ChannelType.CUSTOM } .filter { it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) } @@ -108,9 +104,8 @@ object ChattyBrigadierCommands { it.key in setOf(defaultChannel().key, radiusChannel()?.key, adminChannel()?.key).filterNotNull() }.map { it.key }.toList() ) - } - playerExecutes { - if (channel()?.channelType != ChannelType.CUSTOM) swapChannel(player, channel()) + }.named("channel")) { channel -> + if (channel.channelType != ChannelType.CUSTOM) swapChannel(player, channel) } } "commandspy" { @@ -126,23 +121,15 @@ object ChattyBrigadierCommands { } } "spy" { - playerExecutes { - player.error("Missing channel-argument...") - } - val channel by ChattyChannelArgument().suggests { - suggest(chatty.config.channels.entries - .filter { - it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) - }.sortedBy { + playerExecutes(ChattyChannelArgument().suggests { + suggest(chatty.config.channels.entries.asSequence() + .filter { it.value.channelType != ChannelType.CUSTOM } + .filter { it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) } + .sortedBy { it.key in setOf(defaultChannel().key, radiusChannel()?.key, adminChannel()?.key).filterNotNull() - }.map { it.key } + }.map { it.key }.toList() ) - } - playerExecutes { - val channel = channel() ?: run { - player.sendFormattedMessage(chatty.messages.channels.noChannelWithName) - return@playerExecutes - } + }.named("channel")) { channel -> val spy = player.toGeary().getOrSetPersisting { SpyOnChannels() } when { @@ -166,16 +153,6 @@ object ChattyBrigadierCommands { } "nickname" { val nickMessage = chatty.messages.nicknames - playerExecutes { - player.chattyNickname = null - sender.sendFormattedMessage(nickMessage.selfEmpty) - } - - val nickname by StringArgumentType.greedyString().suggests { - (context.source.executor as? Player)?.chattyNickname?.let { - suggestFiltering(it) - } - } fun String.nicknameTooLong(): Boolean { return when (chatty.config.nicknames.countTagsInLength) { @@ -184,44 +161,61 @@ object ChattyBrigadierCommands { } } - fun handleNickname(player: Player, applyTo: Player, nick: String) { + playerExecutes( + StringArgumentType.string().suggests { + (context.source.executor as? Player)?.chattyNickname?.let { + suggestFiltering(it) + } + }.named("nickname").default { "" }, + ArgumentTypes.player().resolve().map { it.single() }.named("player").default { executor as Player }, + ) { nickname, applyTo -> when { - !player.hasPermission(ChattyPermissions.NICKNAME) -> - player.sendFormattedMessage(nickMessage.selfDenied) - + player == applyTo && nickname.isEmpty() -> { + applyTo.chattyNickname = null + applyTo.sendFormattedMessage(nickMessage.selfEmpty) + } player.uniqueId != applyTo.uniqueId && !player.hasPermission(ChattyPermissions.NICKNAME_OTHERS) -> player.sendFormattedMessage(nickMessage.otherDenied, applyTo) - player.uniqueId != applyTo.uniqueId && nick.isEmpty() -> { + player.uniqueId != applyTo.uniqueId && nickname.isEmpty() -> { applyTo.chattyNickname = null applyTo.sendFormattedMessage(nickMessage.selfEmpty) player.sendFormattedMessage(nickMessage.otherEmpty, applyTo) } - !player.hasPermission(ChattyPermissions.BYPASS_TAG_PERM) && nick.nicknameTooLong() -> + !player.hasPermission(ChattyPermissions.BYPASS_TAG_PERM) && nickname.nicknameTooLong() -> player.sendFormattedMessage(nickMessage.tooLong) - nick.isNotEmpty() -> { - applyTo.chattyNickname = nick + nickname.isNotEmpty() -> { + applyTo.chattyNickname = nickname if (player.uniqueId != applyTo.uniqueId) player.sendFormattedMessage(nickMessage.otherSuccess, player) else player.sendFormattedMessage(nickMessage.selfSuccess) } } } - - playerExecutes { - val nickname = nickname() ?: return@playerExecutes - val applyTo = nickname.substringBefore(" ").toPlayer()?.takeIf { it.uniqueId != player.uniqueId } ?: player - handleNickname(player, applyTo, nickname.removePrefix(applyTo.name.takeIf { applyTo.uniqueId != player.uniqueId } ?: "")) - } } } - ("global" / "g") { handleShortCutChannel(globalChannel()) } - ("local" / "l") { handleShortCutChannel(radiusChannel()) } - ("admin" / "a") { handleShortCutChannel(adminChannel()) } - ("message" / "msg") { handleMessage() } - ("reply" / "r") { handleReply() } + ("global" / "g") { + requiresPermission("") + handleShortCutChannel(globalChannel()) + } + ("local" / "l") { + requiresPermission("") + handleShortCutChannel(radiusChannel()) + } + ("admin" / "a") { + requiresPermission("chatty.channel.admin") + handleShortCutChannel(adminChannel()) + } + ("message" / "msg") { + requiresPermission("") + handleMessage() + } + ("reply" / "r") { + requiresPermission("") + handleReply() + } } } @@ -244,50 +238,19 @@ object ChattyBrigadierCommands { } private fun IdoRootCommand.handleMessage() { - playerExecutes { - player.error("Missing player-argument...") - } - val sendTo by ArgumentTypes.player() - playerExecutes { - player.error("Missing message-argument...") - } - if (chatty.config.chat.disableChatSigning) { - val message by StringArgumentType.greedyString() - playerExecutes { - player.handleSendingPrivateMessage(sendTo().first(), null, message(), false) - } - } else { - val message by ArgumentTypes.signedMessage() - playerExecutes { - chatty.plugin.launch { - val signedMessage = message().resolveSignedMessage("message", context).await() - player.handleSendingPrivateMessage(sendTo().first(), signedMessage, null, false) - } - } + playerExecutes( + ArgumentTypes.player().resolve().map { it.single() }.named("sendTo"), + StringArgumentType.greedyString().named("message") + ) { sendTo, message -> + player.handleSendingPrivateMessage(sendTo, null, message, false) } } private fun IdoRootCommand.handleReply() { - playerExecutes { - player.error("Missing message-argument...") - } - if (chatty.config.chat.disableChatSigning) { - val message by StringArgumentType.greedyString() - playerExecutes { - player.toGeary().get()?.lastMessager?.toPlayer() - ?.let { player.handleSendingPrivateMessage(it, null, message(), true) } - ?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply) - } - } else { - val message by ArgumentTypes.signedMessage() - playerExecutes { - chatty.plugin.launch { - val signedMessage = message().resolveSignedMessage("message", context).await() - player.toGeary().get()?.lastMessager?.toPlayer() - ?.let { player.handleSendingPrivateMessage(it, signedMessage, null, true) } - ?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply) - } - } + playerExecutes(StringArgumentType.greedyString().named("message")) { message -> + player.toGeary().get()?.lastMessager?.toPlayer() + ?.let { player.handleSendingPrivateMessage(it, null, message, true) } + ?: player.sendFormattedMessage(chatty.messages.privateMessages.emptyReply) } } 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 12bb1dc..9a0741c 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 @@ -34,7 +34,7 @@ import java.util.regex.Pattern val alternativePingSounds: List = chatty.config.ping.let { ping -> if ("*" in ping.alternativePingSounds || "all" in ping.alternativePingSounds) - Sound.entries.map { it.key.toString() }.toList() else ping.alternativePingSounds } + Sound.entries.map { it.key().toString() }.toList() else ping.alternativePingSounds } val pingEnabledChannels: List = chatty.config.ping.let { ping -> if ("*" in ping.enabledChannels || "all" in ping.enabledChannels) channelNames() else ping.enabledChannels } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChattyPermissions.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChattyPermissions.kt index 7a239a4..b6b72a2 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChattyPermissions.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChattyPermissions.kt @@ -6,7 +6,6 @@ import net.kyori.adventure.text.minimessage.tag.standard.StandardTags import org.bukkit.permissions.Permission object ChattyPermissions { - const val NICKNAME = "chatty.nickname" const val NICKNAME_OTHERS = "chatty.nickname.others" const val BYPASS_TAG_PERM = "chatty.tags.bypass" const val BYPASS_CHAT_FILTERS_PERM = "chatty.chat.filters.bypass" 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 c29d54f..a5332cb 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 @@ -7,9 +7,10 @@ import com.mineinabyss.chatty.components.ChannelData import com.mineinabyss.chatty.components.CommandSpy import com.mineinabyss.chatty.events.ChattyPlayerChatEvent import com.mineinabyss.chatty.helpers.* +import com.mineinabyss.geary.modules.Geary import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.systems.builders.cache import com.mineinabyss.geary.systems.query.GearyQuery import com.mineinabyss.idofront.textcomponents.serialize import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent @@ -28,10 +29,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent @Suppress("UnstableApiUsage") class ChatListener : Listener { - val plainText = PlainTextComponentSerializer.plainText() - val commandSpyQuery = geary.cache(CommandSpyQuery()) + val commandSpyQuery = gearyPaper.worldManager.global.cache(::CommandSpyQuery) - class CommandSpyQuery : GearyQuery() { + class CommandSpyQuery(world: Geary) : GearyQuery(world) { val player by get() override fun ensure() = this { has() } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/queries/SpyingPlayersQuery.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/queries/SpyingPlayersQuery.kt index a646798..b71bf2c 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/queries/SpyingPlayersQuery.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/queries/SpyingPlayersQuery.kt @@ -1,10 +1,11 @@ package com.mineinabyss.chatty.queries import com.mineinabyss.chatty.components.SpyOnChannels +import com.mineinabyss.geary.modules.Geary import com.mineinabyss.geary.systems.query.GearyQuery import org.bukkit.entity.Player -class SpyingPlayersQuery : GearyQuery() { +class SpyingPlayersQuery(world: Geary) : GearyQuery(world) { val player by get() val spying by get() } diff --git a/gradle.properties b/gradle.properties index f656250..5c0f0d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.8 -idofrontVersion=0.24.21 +idofrontVersion=0.25.17 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2767f56..97f24af 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,11 @@ [versions] -geary = "0.30.10" -velocity = "3.3.0-SNAPSHOT" +geary = "0.31.0" +velocity = "3.4.0-SNAPSHOT" discordsrv = "1.28.0" placeholderapi = "2.11.6" -imageloader = "1.1-SNAPSHOT" [libraries] 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 = { module = "me.clip:placeholderapi", version.ref = "placeholderapi" } -imageloader = { module = "com.combimagnetron:imageloader", version.ref = "imageloader" }