From d648d1ee61c2f3cb90fbe1a4c0539b292f437ab9 Mon Sep 17 00:00:00 2001 From: Boy Date: Sat, 8 Jun 2024 22:12:41 +0200 Subject: [PATCH] refactor: change how to handle command args and custom channels --- .../kotlin/com/mineinabyss/chatty/ChattyChannel.kt | 2 +- .../chatty/commands/ChattyBrigadierCommands.kt | 14 +++++++------- .../mineinabyss/chatty/components/ChannelData.kt | 2 +- .../chatty/listeners/ChattyProxyListener.kt | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyChannel.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyChannel.kt index 95700ab..d5fa3ff 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyChannel.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyChannel.kt @@ -62,7 +62,7 @@ data class ChattyChannel( ChannelType.PERMISSION -> audiences.addAll(onlinePlayers.filter { p -> p.hasPermission(permission) }) // Intended for Guilds etc., want to consider finding a non-permission way for this - ChannelType.PRIVATE -> audiences.add(player) + ChannelType.CUSTOM -> audiences.add(player) } // Add spying players 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 dee0017..eda9add 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 @@ -73,16 +73,16 @@ object ChattyBrigadierCommands { } "channel" { val channel by ChattyChannelArgument().suggests { - suggest(chatty.config.channels.entries - .filter { - it.value.permission.isEmpty() || context.source.sender.hasPermission(it.value.permission) - }.sortedBy { + 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 { - swapChannel(player, channel()) + if (channel()?.channelType != ChannelType.CUSTOM) swapChannel(player, channel()) } } "commandspy" { @@ -258,7 +258,7 @@ object ChattyBrigadierCommands { newChannel == null -> player.sendFormattedMessage(chatty.messages.channels.noChannelWithName) - newChannel.permission.isNotBlank() && !player.hasPermission(newChannel.permission) -> + newChannel.channelType != ChannelType.CUSTOM && newChannel.permission.isNotBlank() && !player.hasPermission(newChannel.permission) -> player.sendFormattedMessage(chatty.messages.channels.missingChannelPermission) else -> { 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 4b41689..231e577 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 @@ -33,5 +33,5 @@ enum class ChannelType { GLOBAL, RADIUS, PERMISSION, - PRIVATE + CUSTOM } 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 11da49a..33010af 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 @@ -49,7 +49,7 @@ class ChattyProxyListener : PluginMessageListener { ChannelType.GLOBAL -> onlinePlayers ChannelType.RADIUS -> canSpy ChannelType.PERMISSION -> onlinePlayers.filter { it.hasPermission(channel.permission) || it in canSpy } - ChannelType.PRIVATE -> onlinePlayers.filter { + ChannelType.CUSTOM -> onlinePlayers.filter { it.toGeary().get()?.withChannelVerified()?.channel == channel || it in canSpy } }.forEach { it.sendMessage(message) }