aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java31
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt26
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt6
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt14
4 files changed, 56 insertions, 21 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
index 2c19b0f..1316aba 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
@@ -1,21 +1,36 @@
package cc.woverflow.chatting.mixin;
+import cc.woverflow.chatting.chat.ChatTab;
import cc.woverflow.chatting.chat.ChatTabs;
import cc.woverflow.chatting.config.ChattingConfig;
import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.client.network.NetHandlerPlayClient;
+import net.minecraft.network.Packet;
+import net.minecraft.network.play.client.C01PacketChatMessage;
+import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
+import org.spongepowered.asm.mixin.injection.Redirect;
-@Mixin(EntityPlayerSP.class)
+@Mixin(value = EntityPlayerSP.class, priority = 0)
public class EntityPlayerSPMixin {
- @ModifyVariable(method = "sendChatMessage", at = @At("HEAD"), ordinal = 0, argsOnly = true)
- private String handleSentMessages(String value) {
- if (value.startsWith("/")) return value;
- if (ChattingConfig.INSTANCE.getChatTabs() && ChatTabs.INSTANCE.getCurrentTab() != null && ChatTabs.INSTANCE.getCurrentTab().getPrefix() != null && !ChatTabs.INSTANCE.getCurrentTab().getPrefix().isEmpty()) {
- return ChatTabs.INSTANCE.getCurrentTab().getPrefix() + value;
+ @Shadow @Final public NetHandlerPlayClient sendQueue;
+
+ @Redirect(method = "sendChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V"))
+ private void handleSentMessages(NetHandlerPlayClient instance, Packet<?> packet, String value) {
+ if (value.startsWith("/")) {
+ sendQueue.addToSendQueue(packet);
+ return;
+ }
+ if (ChattingConfig.INSTANCE.getChatTabs() && !ChatTabs.INSTANCE.getCurrentTabs().isEmpty()) {
+ for (ChatTab tab : ChatTabs.INSTANCE.getTabs()) {
+ if (tab.getPrefix() != null && !tab.getPrefix().isEmpty()) {
+ sendQueue.addToSendQueue(new C01PacketChatMessage(tab.getPrefix() + value));
+ }
+ }
} else {
- return value;
+ sendQueue.addToSendQueue(packet);
}
}
} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index cb95c53..c2329b4 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -16,15 +16,16 @@ object ChatTabs {
private val GSON = GsonBuilder().setPrettyPrinting().create()
private val PARSER = JsonParser()
val tabs = arrayListOf<ChatTab>()
- var currentTab: ChatTab? = null
- set(value) {
- if (value != null) {
- field = value
- if (Minecraft.getMinecraft().theWorld != null) {
- Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat()
- }
+ var currentTabs: ArrayList<ChatTab?> = object : ArrayList<ChatTab?>() {
+ override fun add(element: ChatTab?): Boolean {
+ if (element == null) return false
+ val returnValue = super.add(element)
+ if (Minecraft.getMinecraft().theWorld != null && returnValue) {
+ Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat()
}
+ return returnValue
}
+ }
private var initialized = false
private val tabFile = ConfigUtils.getProfileFile("chattabs.json")
@@ -49,7 +50,8 @@ object ChatTabs {
tabs.forEach {
it.initialize()
}
- currentTab = tabs[0]
+ currentTabs.clear()
+ currentTabs.add(tabs[0])
}
private fun handleFile() {
@@ -171,7 +173,13 @@ object ChatTabs {
}
fun shouldRender(message: IChatComponent): Boolean {
- return currentTab?.shouldRender(message) ?: true
+ if (currentTabs.isEmpty()) return true
+ for (tab in currentTabs) {
+ if (tab?.shouldRender(message) == true) {
+ return true
+ }
+ }
+ return false
}
private fun generateNewFile() {
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index ab52eb9..86db2cc 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -222,9 +222,11 @@ object ChattingConfig : Config(
prefix = ""
)
dummy.initialize()
- ChatTabs.currentTab = dummy
+ ChatTabs.currentTabs.clear()
+ ChatTabs.currentTabs.add(dummy)
} else {
- ChatTabs.currentTab = ChatTabs.tabs[0]
+ ChatTabs.currentTabs.clear()
+ ChatTabs.currentTabs.add(ChatTabs.tabs[0])
}
}
addListener("chatShortcuts") {
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
index f320925..e3b96f1 100644
--- a/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
@@ -1,5 +1,6 @@
package cc.woverflow.chatting.gui.components
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.woverflow.chatting.chat.ChatTab
import cc.woverflow.chatting.chat.ChatTabs
@@ -21,11 +22,20 @@ class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val
}) {
override fun onMousePress() {
- ChatTabs.currentTab = chatTab
+ if (UKeyboard.isShiftKeyDown()) {
+ if (ChatTabs.currentTabs.contains(chatTab)) {
+ ChatTabs.currentTabs.remove(chatTab)
+ } else {
+ ChatTabs.currentTabs.add(chatTab)
+ }
+ } else {
+ ChatTabs.currentTabs.clear()
+ ChatTabs.currentTabs.add(chatTab)
+ }
}
override fun isEnabled(): Boolean {
- return chatTab != ChatTabs.currentTab
+ return ChatTabs.currentTabs.contains(chatTab)
}
companion object {