summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt
blob: d6c2e85c23ebfc19e5898b9104c43b296d48df2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package at.hannibal2.skyhanni.features.commands.tabcomplete

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.api.GetFromSackAPI.commands
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.utils.ChatUtils.eventWithNewMessage
import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni
import at.hannibal2.skyhanni.utils.LorenzUtils

object GetFromSacksTabComplete {

    private val config get() = SkyHanniMod.feature.misc.commands.tabComplete

    fun handleTabComplete(command: String): List<String>? {
        if (!isEnabled()) return null
        if (command !in commands) return null

        return GetFromSackAPI.sackListNames.map { it.replace(" ", "_") }
    }

    //No subscribe since it needs to be called from the GetFromSackAPI
    fun handleUnderlineReplace(event: MessageSendToServerEvent): MessageSendToServerEvent {
        if (!isEnabled()) return event

        if (event.senderIsSkyhanni()) return event

        if (event.splitMessage.size < 3) return event

        val rawName = event.splitMessage.drop(1).dropLast(1).joinToString(" ")
        val realName = rawName.replace("_", " ")
        if (realName == rawName) return event
        if (realName.uppercase() !in GetFromSackAPI.sackListNames) return event
        return event.eventWithNewMessage(event.message.replace(rawName, realName))
    }

    fun isEnabled() = LorenzUtils.inSkyBlock && config.gfsSack
}