Skip to content

Commit

Permalink
feat: add nickname tabcompletion & player-suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 2, 2024
1 parent 58f4dd6 commit 5339c2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter {
}
}

else -> {
else -> {
if (!bypassFormatPerm && !nick.verifyNickLength()) {
sender.sendFormattedMessage(nickMessage.tooLong)
} else {
Expand Down Expand Up @@ -229,31 +229,37 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter {

2 -> when (args[0]) {
"ping" -> listOf("toggle", "sound").filter { s -> s.startsWith(args[1]) }
"spy" ->
chatty.config.channels.entries.filter { s ->
s.key.startsWith(args[1], true) && s.value.channelType != ChannelType.GLOBAL
}.map { it.key }
"spy" -> chatty.config.channels.entries.filter { s ->
s.key.startsWith(args[1], true) && s.value.channelType != ChannelType.GLOBAL
}.map { it.key }

"nickname" -> (onlinePlayers.takeIf { args[1].startsWith(otherPrefix) }?.map { otherPrefix + it }
?: (sender as? Player)?.let { player -> listOf(player.chattyNickname ?: player.name) }
?: emptyList()).filter { s -> s.startsWith(args[1], true) }
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)
}
args[0] == "ping" && args[1] == "sound" ->
getAlternativePingSounds.filter { s -> s.startsWith(args[2], true) }

args[0] == "nickname" -> args[1].drop(1).takeIf { args[1].startsWith(otherPrefix) && it.isNotEmpty() }?.toPlayer()?.let { player ->
listOf(player.chattyNickname ?: player.name).filter { s -> s.startsWith(args[2], true) }
} ?: emptyList()

else -> emptyList()
}

else -> emptyList()
}
}

"message", "msg" ->
when (args.size) {
0, 1 -> onlinePlayers.filter { s -> s.startsWith(args[0], true) }.take(25)
else -> emptyList()
}

else -> emptyList()
}
}
Expand Down Expand Up @@ -332,19 +338,22 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter {
}



companion object {
private fun CommandSender.sendFormattedMessage(message: String, optionalPlayer: Player? = null) =
(optionalPlayer ?: this as? Player)?.let { player ->
this.sendMessage(translatePlaceholders(player, message).miniMsg(player.buildTagResolver(true)))
}

private fun Player.sendFormattedPrivateMessage(messageFormat: String, message: String, receiver: Player) =
this.sendMessage(Component.textOfChildren(
translatePlaceholders(receiver, messageFormat).miniMsg(receiver.buildTagResolver(true)),
message.miniMsg(receiver.buildTagResolver(true)))
this.sendMessage(
Component.textOfChildren(
translatePlaceholders(receiver, messageFormat).miniMsg(receiver.buildTagResolver(true)),
message.miniMsg(receiver.buildTagResolver(true))
)
)
private fun CommandSender.sendConsoleMessage(message: String) = this.sendMessage(message.miniMsg().parseTags(null, true))

private fun CommandSender.sendConsoleMessage(message: String) =
this.sendMessage(message.miniMsg().parseTags(null, true))

private fun List<String>.removeFirstArgumentOfStringList(): String =
this.filter { it != this.first() }.toSentence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ fun String.verifyNickLength(): Boolean {
}
}

fun List<String>.getPlayerToNick(): Player? = Bukkit.getPlayer(
this.first().replace(chatty.config.nicknames.nickNameOtherPrefix.toString(), "")
)
fun List<String>.getPlayerToNick(): Player? =
this.first().replace(chatty.config.nicknames.nickNameOtherPrefix.toString(), "").toPlayer()

fun String.removePlayerToNickFromString(): String =
this.split(" ").filter { it != this.split(" ").first() }.toSentence()

0 comments on commit 5339c2d

Please sign in to comment.