Skip to content

Commit

Permalink
improved rename command auto-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrr committed Oct 25, 2022
1 parent 16ab910 commit 547db77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/me/apyr/chatemotes/EventListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class EventListener : Listener {
return
}

val emotes: Map<String, Emote> = plugin.emotes.takeIf { it.isNotEmpty() } ?: return
e.message = formatMessage(e.message, emotes)
e.message = formatMessage(e.message, plugin.emotes.takeIf { it.isNotEmpty() } ?: return)
}

@EventHandler
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/me/apyr/chatemotes/commands/RenameCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ class RenameCommand : ChatEmotesCommand {

override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> {
return when {
args.size == 1 && args[0].isEmpty() -> ChatEmotes.getInstance().emotes.values.map { it.name }
args.size == 1 -> ChatEmotes.getInstance().emotes.values.let { emotes ->
val term: String? = args.firstOrNull()?.takeIf { it.isNotEmpty() }
if (term != null) {
emotes.filter { e -> e.name.contains(term, ignoreCase = true) }
} else {
emotes
}
}.map { it.name }
args.size == 2 && args[1].isEmpty() -> listOf("<new>")
else -> emptyList()
}
Expand Down

0 comments on commit 547db77

Please sign in to comment.