aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt
blob: c3baa9ea293ef55675bddb551ac3d141a1ddfe94 (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 com.dulkirfabric.util

import com.dulkirfabric.DulkirModFabric.mc
import net.minecraft.text.Text

object TextUtils {
    const val CHAT_PREFIX = "§f<§3DulkirMod§f>§r"
    fun info(text: String, prefix: Boolean = true) {
        if (mc.player == null) return

        val textPrefix = if (prefix) "${CHAT_PREFIX} " else ""
        mc.inGameHud.chatHud.addMessage(Text.literal("$textPrefix$text§r"))
    }

    fun toggledMessage(message: String, state: Boolean) {
        val stateText = if (state) "§aON" else "§cOFF"
        info("§9Toggled $message §8[$stateText§8]§r")
    }

    val Text.unformattedString
        get() = string.replace("§.".toRegex(), "")

    fun sendPartyChatMessage(message: String) {
        this.sendCommand("/pc $message")
    }

    fun sendMessage(message: String) {
        mc.player?.networkHandler?.sendChatMessage(message)
    }

    fun sendCommand(command: String) {
        mc.player?.networkHandler?.sendChatCommand(command)
    }

    fun stripColorCodes(string: String): String {
        return string.replace("§.".toRegex(), "")
    }
}