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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* Skytils - Hypixel Skyblock Quality of Life Mod
* Copyright (C) 2021 Skytils
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package skytils.skytilsmod.features.impl.handlers
import gg.essential.universal.UResolution
import net.minecraft.client.gui.GuiChat
import net.minecraft.network.play.server.S02PacketChat
import net.minecraft.util.IChatComponent
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
import skytils.skytilsmod.Skytils
import skytils.skytilsmod.Skytils.Companion.mc
import skytils.skytilsmod.events.PacketEvent
import skytils.skytilsmod.gui.elements.CleanButton
import skytils.skytilsmod.mixins.extensions.ExtensionChatStyle
import skytils.skytilsmod.mixins.transformers.accessors.AccessorGuiChat
import skytils.skytilsmod.mixins.transformers.accessors.AccessorGuiNewChat
import skytils.skytilsmod.utils.Utils
object ChatTabs {
var selectedTab = ChatTab.ALL
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onChat(event: PacketEvent.ReceiveEvent) {
if (!Utils.isOnHypixel || !Skytils.config.chatTabs || event.packet !is S02PacketChat) return
val style = event.packet.chatComponent.chatStyle
style as ExtensionChatStyle
if (style.chatTabType == null) {
style.chatTabType = ChatTab.values().filter { it.isValid(event.packet.chatComponent) }.toTypedArray()
}
}
fun shouldAllow(component: IChatComponent): Boolean {
if (!Utils.isOnHypixel || !Skytils.config.chatTabs) return true
val style = component.chatStyle
style as ExtensionChatStyle
if (style.chatTabType == null) {
style.chatTabType = ChatTab.values().filter { it.isValid(component) }.toTypedArray()
}
return style.chatTabType!!.contains(selectedTab)
}
@SubscribeEvent
fun onOpenGui(event: GuiOpenEvent) {
if (!Skytils.config.chatTabs || !Skytils.config.preFillChatTabCommands || !Utils.isOnHypixel || event.gui !is GuiChat) return
if ((event.gui as AccessorGuiChat).defaultInputFieldText.isBlank()) {
(event.gui as AccessorGuiChat).defaultInputFieldText = when (selectedTab) {
ChatTab.ALL -> "/ac "
ChatTab.PARTY -> "/pc "
ChatTab.GUILD -> "/gc "
ChatTab.PRIVATE -> "/r "
}
}
}
@SubscribeEvent
fun onScreenEvent(event: GuiScreenEvent) {
if (!Skytils.config.chatTabs || !Utils.isOnHypixel || event.gui !is GuiChat) return
val chat = mc.ingameGUI.chatGUI
chat as AccessorGuiNewChat
when (event) {
is GuiScreenEvent.InitGuiEvent.Post -> {
event.buttonList.addAll(ChatTab.buttons.values)
}
is GuiScreenEvent.ActionPerformedEvent.Pre -> {
ChatTab.buttons.entries.find {
it.value == event.button
}?.let {
selectedTab = it.key
mc.ingameGUI.chatGUI.refreshChat()
if (Skytils.config.autoSwitchChatChannel) {
Skytils.sendMessageQueue.addFirst(
when (selectedTab) {
ChatTab.ALL -> "/chat a"
ChatTab.PARTY -> "/chat p"
ChatTab.GUILD -> "/chat g"
else -> ""
}
)
}
}
}
is GuiScreenEvent.DrawScreenEvent.Pre -> {
ChatTab.buttons.entries.forEach { (c, b) ->
b.enabled = c != selectedTab
b.yPosition =
UResolution.scaledHeight - chat.drawnChatLines.size.coerceAtMost(chat.lineCount) * 9 - 50 - 9
}
}
}
}
@SubscribeEvent
fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) {
mc.ingameGUI.chatGUI.refreshChat()
}
enum class ChatTab(text: String, val isValid: (IChatComponent) -> Boolean) {
ALL("A", { true }),
PARTY("P", {
val formatted = it.formattedText
formatted.startsWith("§r§9Party §8> ") || formatted.startsWith("§r§9P §8> ")
}),
GUILD("G", {
val formatted = it.formattedText
formatted.startsWith("§r§2Guild > ") || formatted.startsWith("§r§2G > ")
}),
PRIVATE("PM", {
val formatted = it.formattedText
formatted.startsWith("§dTo ") || formatted.startsWith("§dFrom ")
});
val button = CleanButton(-69420, 2 + 20 * ordinal, 0, 20, 20, text)
companion object {
val buttons by lazy { values().associateWith { it.button } }
}
}
}
|