diff options
author | Brady <thatgravyboat@gmail.com> | 2024-04-30 07:40:01 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 12:10:01 +0200 |
commit | 5ec11173f2124e5069d93c16e5ae9b25658c31e9 (patch) | |
tree | fa83f741a514bfdebd148366c9933569b71a43b7 /src/main/java | |
parent | ca4e3dcf0bdf78a48131cd2e925b81904cd86a4b (diff) | |
download | skyhanni-5ec11173f2124e5069d93c16e5ae9b25658c31e9.tar.gz skyhanni-5ec11173f2124e5069d93c16e5ae9b25658c31e9.tar.bz2 skyhanni-5ec11173f2124e5069d93c16e5ae9b25658c31e9.zip |
Improvement: Add autocomplete for party commands (#1598)
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt | 28 |
1 files changed, 19 insertions, 9 deletions
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) + } } |