Skip to content

Commit

Permalink
move some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Sep 11, 2022
1 parent a2103f3 commit c9adbe7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter {
}
}

private fun Player.sendFormattedMessage(message: String, optionalPlayer: Player? = null) =
this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message).serialize().miniMsg())

private fun Player.handleSendingPrivateMessage(player: Player, arguments: List<String>, isReply: Boolean = false) {
if (!chattyConfig.privateMessages.enabled) {
this.sendFormattedMessage(chattyMessages.privateMessages.disabled)
Expand All @@ -343,25 +346,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter {
}
}

private fun Player.swapChannelCommand(channelId: String) {
val newChannel = getChannelFromId(channelId)

if (newChannel == null) {
sendFormattedMessage(chattyMessages.channels.noChannelWithName)
} else if (!checkPermission(newChannel.permission)) {
sendFormattedMessage(chattyMessages.channels.missingChannelPermission)
} else {
chattyData.channelId = channelId
chattyData.lastChannelUsed = channelId
sendFormattedMessage(chattyMessages.channels.channelChanged)
}
}

private fun Player.sendFormattedMessage(message: String) =
this.sendMessage(translatePlaceholders(this, message).serialize().miniMsg())

private fun Player.sendFormattedMessage(message: String, optionalPlayer: Player? = null) =
this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message).serialize().miniMsg())

private fun Player.sendFormattedPrivateMessage(messageFormat: String, message: String, receiver: Player) =
this.sendMessage((translatePlaceholders(receiver, messageFormat).serialize() + message).miniMsg())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,22 @@ fun List<String>.toSentence() = this.joinToString(" ")
fun String.toPlayer(): Player? {
return Bukkit.getPlayer(this)
}

fun Player.swapChannelCommand(channelId: String) {
val newChannel = getChannelFromId(channelId)

if (newChannel == null) {
sendFormattedMessage(chattyMessages.channels.noChannelWithName)
} else if (!checkPermission(newChannel.permission)) {
sendFormattedMessage(chattyMessages.channels.missingChannelPermission)
} else {
chattyData.channelId = channelId
chattyData.lastChannelUsed = channelId
sendFormattedMessage(chattyMessages.channels.channelChanged)
}
}

fun Player.sendFormattedMessage(message: String) =
this.sendMessage(translatePlaceholders(this, message).serialize().miniMsg())


0 comments on commit c9adbe7

Please sign in to comment.