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 0f612c6..6061052 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt @@ -163,7 +163,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { .forEach { channelName -> channelName { playerAction { - player.swapChannelCommand(chatty.config.channels[channelName]) + swapChannel(player, chatty.config.channels[channelName]) } } } @@ -267,7 +267,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { channel.value.permission.isNotBlank() && !hasPermission(channel.value.permission) -> sendFormattedMessage(chatty.messages.channels.missingChannelPermission) - arguments.isEmpty() -> swapChannelCommand(channel.value) + arguments.isEmpty() -> swapChannel(this, channel.value) else -> { toGeary().setPersisting(chattyData.copy(channelId = channel.key, lastChannelUsedId = channel.key)) chatty.plugin.launch(chatty.plugin.asyncDispatcher) { @@ -331,35 +331,42 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { } } - private fun Player.sendFormattedMessage(message: String, optionalPlayer: Player? = null) = - this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message).parseTags(this, true)) - private fun Player.sendFormattedPrivateMessage(messageFormat: String, message: String, receiver: Player) = - this.sendMessage( - (translatePlaceholders(receiver, messageFormat).serialize() + message) - .parseTags(receiver, true) - ) - private fun CommandSender.sendConsoleMessage(message: String) = this.sendMessage(message.parseTags(null, true)) + companion object { + private fun Player.sendFormattedMessage(message: String, optionalPlayer: Player? = null) = + this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message).parseTags(this, true)) - private fun List.removeFirstArgumentOfStringList(): String = - this.filter { it != this.first() }.toSentence() + private fun Player.sendFormattedPrivateMessage(messageFormat: String, message: String, receiver: Player) = + this.sendMessage( + (translatePlaceholders(receiver, messageFormat).serialize() + message) + .parseTags(receiver, true) + ) + private fun CommandSender.sendConsoleMessage(message: String) = this.sendMessage(message.parseTags(null, true)) + private fun List.removeFirstArgumentOfStringList(): String = + this.filter { it != this.first() }.toSentence() - private fun Player.swapChannelCommand(newChannel: ChattyChannel?) { - when { - newChannel == null -> - sendFormattedMessage(chatty.messages.channels.noChannelWithName) + fun swapChannel(player: Player, newChannel: ChattyChannel?) { + when { + newChannel == null -> + player.sendFormattedMessage(chatty.messages.channels.noChannelWithName) - newChannel.permission.isNotBlank() && !hasPermission(newChannel.permission) -> - sendFormattedMessage(chatty.messages.channels.missingChannelPermission) + newChannel.permission.isNotBlank() && !player.hasPermission(newChannel.permission) -> + player.sendFormattedMessage(chatty.messages.channels.missingChannelPermission) - else -> { - val chattyData = toGeary().get() ?: return - toGeary().setPersisting(chattyData.copy(channelId = newChannel.key, lastChannelUsedId = newChannel.key)) - sendFormattedMessage(chatty.messages.channels.channelChanged) + else -> { + val gearyPlayer = player.toGeary() + val chattyData = gearyPlayer.get() ?: return + gearyPlayer.setPersisting( + chattyData.copy( + channelId = newChannel.key, + lastChannelUsedId = newChannel.key + ) + ) + player.sendFormattedMessage(chatty.messages.channels.channelChanged) + } } } } - }