diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-22 11:07:28 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-22 11:07:28 +0700 |
commit | c84baaa1586da7aafdd3d3ddf2dcd3543b2444a2 (patch) | |
tree | ad8d92e48124e70325a0948fac473e741c9667b3 /src/main/kotlin/com | |
parent | 4540fdbbf083fa5300667cf443799de04df5f24e (diff) | |
download | Chatting-c84baaa1586da7aafdd3d3ddf2dcd3543b2444a2.tar.gz Chatting-c84baaa1586da7aafdd3d3ddf2dcd3543b2444a2.tar.bz2 Chatting-c84baaa1586da7aafdd3d3ddf2dcd3543b2444a2.zip |
finish up chat tabs + chat message copying
Diffstat (limited to 'src/main/kotlin/com')
5 files changed, 64 insertions, 42 deletions
diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt index 1b74fa0..0bf6831 100644 --- a/src/main/kotlin/com/raeids/stratus/Stratus.kt +++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt @@ -3,7 +3,6 @@ package com.raeids.stratus import com.raeids.stratus.command.StratusCommand import com.raeids.stratus.config.StratusConfig import com.raeids.stratus.hook.ChatTabs -import com.raeids.stratus.hook.GuiNewChatHook import com.raeids.stratus.mixin.GuiNewChatAccessor import com.raeids.stratus.updater.Updater import com.raeids.stratus.utils.RenderHelper @@ -14,7 +13,6 @@ import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.GuiChat import net.minecraft.client.settings.KeyBinding import net.minecraft.client.shader.Framebuffer -import net.minecraftforge.client.event.MouseEvent import net.minecraftforge.common.MinecraftForge.EVENT_BUS import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Mod @@ -23,8 +21,6 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.input.Keyboard -import java.awt.Toolkit -import java.awt.datatransfer.StringSelection import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -67,18 +63,6 @@ object Stratus { } @SubscribeEvent - fun onMouseClick(event: MouseEvent) { - val hook = Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook - if (hook.shouldCopy()) { - try { - Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(hook.copyString()), null) - } catch (e: Exception) { - e.printStackTrace() - } - } - } - - @SubscribeEvent fun onTickEvent(event: TickEvent.ClientTickEvent) { if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) { if (doTheThing) { diff --git a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt index 7a2dc65..905f847 100644 --- a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt +++ b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt @@ -1,6 +1,8 @@ package com.raeids.stratus.config import com.raeids.stratus.Stratus +import com.raeids.stratus.hook.ChatTab +import com.raeids.stratus.hook.ChatTabs import com.raeids.stratus.updater.DownloadGui import com.raeids.stratus.updater.Updater import gg.essential.api.EssentialAPI @@ -15,12 +17,36 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra type = PropertyType.SWITCH, name = "Chat Searching", description = "Add a chat search bar.", - category = "General" + category = "Searching" ) var chatSearch = true @Property( type = PropertyType.SWITCH, + name = "Chat Tabs", + description = "Add chat tabs.", + category = "Tabs" + ) + var chatTabs = true + get() { + if (!field) return false + return if (hypixelOnlyChatTabs) { + EssentialAPI.getMinecraftUtil().isHypixel() + } else { + true + } + } + + @Property( + type = PropertyType.SWITCH, + name = "Enable Only on Hypixel", + description = "Enable chat tabs only in Hypixel.", + category = "Tabs" + ) + var hypixelOnlyChatTabs = true + + @Property( + type = PropertyType.SWITCH, name = "Show Update Notification", description = "Show a notification when you start Minecraft informing you of new updates.", category = "Updater" @@ -44,5 +70,9 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra init { initialize() + registerListener("chatTabs") { funny: Boolean -> + chatTabs = funny + ChatTabs.currentTab = ChatTab("ALL", false, null, null, null, null, null, "") + } } }
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatRegexes.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatRegexes.kt new file mode 100644 index 0000000..fd743ea --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatRegexes.kt @@ -0,0 +1,11 @@ +package com.raeids.stratus.hook + +data class ChatRegexes(val regexList: List<String>?) { + val compiledRegexList: MutableList<Regex> = arrayListOf() + + init { + regexList?.forEach { + compiledRegexList.add(Regex(it)) + } + } +} diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt index f2fd0fc..3609fdc 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt @@ -3,39 +3,38 @@ package com.raeids.stratus.hook import com.google.gson.annotations.SerializedName import kotlinx.coroutines.runBlocking import net.minecraft.client.Minecraft +import net.minecraft.util.EnumChatFormatting +import net.minecraft.util.IChatComponent data class ChatTab( - @SerializedName("name") val name: String, + val name: String, + val unformatted: Boolean, @SerializedName("starts") val startsWith: List<String>?, - @SerializedName("contains") val contains: List<String>?, + val contains: List<String>?, @SerializedName("ends") val endsWith: List<String>?, - @SerializedName("equals") val equals: List<String>?, + val equals: List<String>?, @SerializedName("regex") val uncompiledRegex: List<String>?, - @SerializedName("prefix") val prefix: String + val prefix: String ) { lateinit var button: CleanButton - var compiledRegex: MutableList<Regex> = arrayListOf() + lateinit var compiledRegex: ChatRegexes //Ugly hack to make GSON not make button / regex null fun initialize() { - compiledRegex = arrayListOf() + compiledRegex = ChatRegexes(uncompiledRegex) val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name) button = CleanButton(653452, runBlocking { val returnValue = x - 2 x += 6 + width return@runBlocking returnValue }, 0, width + 4, 12, this) - if (uncompiledRegex != null && uncompiledRegex.isNotEmpty()) { - uncompiledRegex.forEach { - compiledRegex.add(Regex(it)) - } - } } - fun shouldRender(message: String): Boolean { + fun shouldRender(chatComponent: IChatComponent): Boolean { if (startsWith == null && equals == null && endsWith == null && contains == null && uncompiledRegex == null) { return true } + val message = if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText equals?.forEach { if (message == it) { return true @@ -56,15 +55,9 @@ data class ChatTab( return true } } - if ((uncompiledRegex != null) && uncompiledRegex.isNotEmpty()) { - try { - compiledRegex.forEach { - if (it.matches(message)) { - return true - } - } - } catch (_: Throwable) { - + compiledRegex.compiledRegexList.forEach { + if (it.matches(message)) { + return true } } return false diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt index 0e845d5..b162671 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt @@ -3,6 +3,7 @@ package com.raeids.stratus.hook import com.google.gson.* import com.raeids.stratus.Stratus import net.minecraft.client.Minecraft +import net.minecraft.util.IChatComponent import java.io.File object ChatTabs { @@ -43,7 +44,7 @@ object ChatTabs { currentTab = tabs[0] } - fun shouldRender(message: String): Boolean { + fun shouldRender(message: IChatComponent): Boolean { return currentTab?.shouldRender(message) ?: true } @@ -57,9 +58,10 @@ object ChatTabs { } private fun generateDefaultTabs(): JsonArray { - val all = ChatTab("ALL", null, null, null, null, null, "") + val all = ChatTab("ALL", false, null, null, null, null, null, "/ac ") val party = ChatTab( "PARTY", + false, listOf("§r§9Party §8> ", "§r§9P §8> ", "§eThe party was transferred to §r", "§eKicked §r"), null, listOf( @@ -78,7 +80,8 @@ object ChatTabs { ) val guild = ChatTab( "GUILD", - listOf("§r§2Guild > ", "§r§2G > "), + true, + listOf("Guild >", "G >"), null, null, null, @@ -87,7 +90,8 @@ object ChatTabs { ) val pm = ChatTab( "PM", - listOf("§dTo ", "§dFrom "), + true, + listOf("To ", "From "), null, null, null, |