aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/keybinds/SendLastMessageKeybind.kt
blob: 9a0a4f9d9abbd82fee7e841da92f7cec1091c7ef (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
package com.ambientaddons.features.keybinds

import AmbientAddons.Companion.keyBinds
import AmbientAddons.Companion.mc
import com.ambientaddons.events.MessageSentEvent
import com.ambientaddons.utils.SBLocation
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.InputEvent

object SendLastMessageKeybind {
    var lastMessage: String? = null

    @SubscribeEvent
    fun onSendChat(event: MessageSentEvent) {
        if (!SBLocation.onHypixel) return
        if (event.message.startsWith("/pc", ignoreCase = true)) {
            lastMessage = event.message.runCatching {
                substring(4 until event.message.length)
            }.getOrNull()
        } else if (!event.message.startsWith("/")) {
            lastMessage = event.message
        }
    }

    @SubscribeEvent
    fun onKey(event: InputEvent.KeyInputEvent) {
        if (!SBLocation.onHypixel) return
        if (keyBinds["spamKey"]!!.isPressed && lastMessage != null) {
            mc.thePlayer.sendChatMessage("/pc $lastMessage")
        }
    }
}