From 5ec11173f2124e5069d93c16e5ae9b25658c31e9 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 30 Apr 2024 07:40:01 -0230 Subject: Improvement: Add autocomplete for party commands (#1598) --- .../features/commands/PartyChatCommands.kt | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index 8bb8e46ea..aa38f90b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.features.misc.PartyCommandsConfig import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent +import at.hannibal2.skyhanni.events.TabCompletionEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark @@ -72,26 +73,35 @@ object PartyChatCommands { } } - private val commandBeginChars = ".!?".toSet() + private val commandPrefixes = ".!?".toSet() @SubscribeEvent fun onPartyCommand(event: PartyChatEvent) { - if (event.message.firstOrNull() !in commandBeginChars) - return + if (event.message.firstOrNull() !in commandPrefixes) return val commandLabel = event.message.substring(1).substringBefore(' ') val command = indexedPartyChatCommands[commandLabel.lowercase()] ?: return val name = event.cleanedAuthor - if (name == LorenzUtils.getPlayerName()) { - return - } + + if (name == LorenzUtils.getPlayerName()) return if (!command.isEnabled()) return - if (command.requiresPartyLead && PartyAPI.partyLeader != LorenzUtils.getPlayerName()) { - return - } + if (command.requiresPartyLead && PartyAPI.partyLeader != LorenzUtils.getPlayerName()) return if (!isTrustedUser(name)) { ChatUtils.chat("§cIgnoring chat command from $name. Change your party chat command settings or /friend (best) them.") return } command.executable(event) } + + @SubscribeEvent + fun onTabComplete(event: TabCompletionEvent) { + if (PartyAPI.partyLeader == null) return + val prefix = event.fullText.firstOrNull() ?: return + if (prefix !in commandPrefixes) return + + val commandText = event.fullText.substring(1) + indexedPartyChatCommands.keys + .filter { it.startsWith(commandText) } + .map { "$prefix$it" } + .forEach(event::addSuggestion) + } } -- cgit