diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | docs/chattabs.md | 22 | ||||
-rw-r--r-- | settings.gradle | 7 | ||||
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java | 2 | ||||
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java | 2 | ||||
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java | 9 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt | 27 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt | 9 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt | 27 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt | 12 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt | 47 |
15 files changed, 150 insertions, 33 deletions
@@ -26,4 +26,5 @@ build # other run .DS_Store -Thumbs.db
\ No newline at end of file +Thumbs.db +.vscode
\ No newline at end of file diff --git a/build.gradle b/build.gradle index 430a98a..e4b3b7f 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { } version = mod_version -group = "com.example" +group = "cc.woverflow" archivesBaseName = mod_name blossom { diff --git a/docs/chattabs.md b/docs/chattabs.md index 0738310..4b9cde6 100644 --- a/docs/chattabs.md +++ b/docs/chattabs.md @@ -12,15 +12,16 @@ something like this: "enabled": true, "name": "ALL", "unformatted": false, + "lowercase": false, "color": 14737632, "hovered_color": 16777120, - "selected_color": 10526880, - "prefix": "" + "selected_color": 10526880 }, { "enabled": true, "name": "PARTY", "unformatted": false, + "lowercase": false, "starts": [ "§r§9Party §8> ", "§r§9P §8> ", @@ -90,6 +91,7 @@ something like this: "enabled": true, "name": "GUILD", "unformatted": true, + "lowercase": false, "starts": [ "Guild >", "G >" @@ -103,6 +105,7 @@ something like this: "enabled": true, "name": "PM", "unformatted": true, + "lowercase": false, "starts": [ "To ", "From " @@ -113,7 +116,7 @@ something like this: "prefix": "/r " } ], - "version": 4 + "version": 5 } ``` @@ -222,17 +225,22 @@ The `selected_color` property allows you to change the color of the chat tab tex over all the other color properties. Like the other color properties, it is in RGBA format. The `prefix` property appends the prefix to any message sent while in the specific chat tab **if it is not a command**. -This can be used to automatically send messages in a specific channel in servers, like in Hypixel. +This can be used to automatically send messages in a specific channel in servers, like in Hypixel. This is no longer required as of version 5. + +The `lowercase` property makes the message trigger lowercase. ## Chat Tabs JSON Changelogs +### Version 5 (Chatting 1.4.0 [04363f5]) +- The `prefix` property is no longer a required property. +- Added `lowercase` property -### Version 4 +### Version 4 (Chatting 1.4.0 [eece3cb]) - Added color text options (`color`, `hovered_color`, and `selected_color`) - `version` is now actually an integer -### Version 3 +### Version 3 (Chatting 1.4.0-alpha1) - Added `ignore_` options (`ignore_starts`, `ignore_ends`, `ignore_equals`, and `ignore_regex`) -### Version 2 +### Version 2 (1.0.0) - Added `enabled` property
\ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 6b018a3..4f8d00d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,13 +3,6 @@ pluginManagement { gradlePluginPortal() maven { url = "https://repo.woverflow.cc" } } - resolutionStrategy { - eachPlugin { - if (requested.id.id == "cc.woverflow.loom") { - useModule("cc.woverflow:architectury-loom:${requested.version}") - } - } - } } rootProject.name = mod_name
\ No newline at end of file diff --git a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java index 42c5579..2c19b0f 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java @@ -12,7 +12,7 @@ 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().isEmpty()) { + if (ChattingConfig.INSTANCE.getChatTabs() && ChatTabs.INSTANCE.getCurrentTab() != null && ChatTabs.INSTANCE.getCurrentTab().getPrefix() != null && !ChatTabs.INSTANCE.getCurrentTab().getPrefix().isEmpty()) { return ChatTabs.INSTANCE.getCurrentTab().getPrefix() + value; } else { return value; diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java index e3edf95..1774f82 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java @@ -5,6 +5,7 @@ import cc.woverflow.chatting.chat.ChatShortcuts; import cc.woverflow.chatting.chat.ChatTab; import cc.woverflow.chatting.chat.ChatTabs; import cc.woverflow.chatting.config.ChattingConfig; +import cc.woverflow.chatting.gui.components.ClearButton; import cc.woverflow.chatting.gui.components.ScreenshotButton; import cc.woverflow.chatting.gui.components.SearchButton; import cc.woverflow.chatting.hook.GuiNewChatHook; @@ -51,6 +52,7 @@ public abstract class GuiChatMixin extends GuiScreen { buttonList.add(searchButton); } buttonList.add(new ScreenshotButton()); + buttonList.add(new ClearButton()); if (ChattingConfig.INSTANCE.getChatTabs()) { for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) { buttonList.add(chatTab.getButton()); diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java index e9acce1..6cf58ef 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java @@ -72,6 +72,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci); } + @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;scroll(I)V"), to = @At(value = "INVOKE", target = "Ljava/util/List;size()I")), cancellable = true) + private void handleAddDrawnLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { + ci.cancel(); + ChatLine chatLine = new ChatLine(updateCounter, chatComponent, chatLineId); + RenderUtils.messages.put(chatLine, System.currentTimeMillis()); + this.drawnChatLines.add(0, chatLine); + } + @Inject(method = "drawChat", at = @At("HEAD")) private void checkScreenshotKeybind(int j2, CallbackInfo ci) { if (Chatting.INSTANCE.getKeybind().isPressed()) { @@ -133,6 +141,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) private int redirectDrawString(FontRenderer instance, String text, float x, float y, int color) { + RenderUtils.showTimestamp(); return ModCompatHooks.redirectDrawString(text, x, y, color); } diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt index 2cd4418..50de1f4 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt @@ -5,11 +5,13 @@ import com.google.gson.annotations.SerializedName import net.minecraft.client.Minecraft import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent +import java.util.* data class ChatTab( val enabled: Boolean, val name: String, val unformatted: Boolean, + val lowercase: Boolean?, @SerializedName("starts") val startsWith: List<String>?, val contains: List<String>?, @SerializedName("ends") val endsWith: List<String>?, @@ -23,7 +25,7 @@ data class ChatTab( val color: Int?, @SerializedName("hovered_color") val hoveredColor: Int?, @SerializedName("selected_color") val selectedColor: Int?, - val prefix: String, + val prefix: String?, ) { lateinit var button: TabButton lateinit var compiledRegex: ChatRegexes @@ -43,7 +45,11 @@ data class ChatTab( fun shouldRender(chatComponent: IChatComponent): Boolean { val message = - if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText + (if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText).let { + if (lowercase == true) it.lowercase( + Locale.ENGLISH + ) else it + } ignoreStartsWith?.forEach { if (message.startsWith(it)) { return false diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index 99a8999..cdec672 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -45,26 +45,37 @@ object ChatTabs { applyVersion2Changes(it.asJsonObject) applyVersion3Changes(it.asJsonObject) applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(chatTabJson.toString()) + tabFile.writeText(GSON.toJson(chatTabJson)) } 2 -> { // ver 3 adds ignore_ chatTabJson.tabs.forEach { applyVersion3Changes(it.asJsonObject) applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(chatTabJson.toString()) + tabFile.writeText(GSON.toJson(chatTabJson)) } 3 -> { // ver 4 adds color options chatTabJson.tabs.forEach { applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) } chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(chatTabJson.toString()) + tabFile.writeText(GSON.toJson(chatTabJson)) + } + 4 -> { + // ver 5 adds lowercase + chatTabJson.tabs.forEach { + applyVersion5Changes(it.asJsonObject) + } + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) } } chatTabJson.tabs.forEach { @@ -103,6 +114,10 @@ object ChatTabs { json.addProperty("selected_color", TabButton.selectedColor) } + private fun applyVersion5Changes(json: JsonObject) { + json.addProperty("lowercase", false) + } + fun shouldRender(message: IChatComponent): Boolean { return currentTab?.shouldRender(message) ?: true } @@ -113,7 +128,7 @@ object ChatTabs { val defaultTabs = generateDefaultTabs() jsonObject.add("tabs", defaultTabs) jsonObject.addProperty("version", ChatTabsJson.VERSION) - tabFile.writeText(jsonObject.toString()) + tabFile.writeText(GSON.toJson(jsonObject)) } private fun generateDefaultTabs(): JsonArray { @@ -121,6 +136,7 @@ object ChatTabs { true, "ALL", false, + false, null, null, null, @@ -140,6 +156,7 @@ object ChatTabs { true, "PARTY", false, + false, listOf("§r§9Party §8> ", "§r§9P §8> ", "§eThe party was transferred to §r", "§eKicked §r"), null, listOf( @@ -208,6 +225,7 @@ object ChatTabs { true, "GUILD", true, + false, listOf("Guild >", "G >"), null, null, @@ -227,6 +245,7 @@ object ChatTabs { true, "PM", true, + false, listOf("To ", "From "), null, null, diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt index 6954b8e..b239bbd 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt @@ -10,6 +10,6 @@ data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version } companion object { - const val VERSION = 4 + const val VERSION = 5 } }
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index ae2187f..e80fa94 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -80,6 +80,14 @@ object ChattingConfig : @Property( type = PropertyType.SWITCH, + name = "Show Timestamp", + description = "Show message timestamp on hover.", + category = "General" + ) + var showTimestamp = false + + @Property( + type = PropertyType.SWITCH, name = "Custom Chat Height", description = "Allows you to change the height of chat to heights greater than before.", category = "Chat Window" @@ -183,6 +191,7 @@ object ChattingConfig : true, "ALL", false, + false, null, null, null, diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt new file mode 100644 index 0000000..3035a98 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ClearButton.kt @@ -0,0 +1,27 @@ +package cc.woverflow.chatting.gui.components + +import cc.woverflow.chatting.Chatting +import gg.essential.universal.UResolution +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.Gui +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ResourceLocation + +class ClearButton : + CleanButton(13379014, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 27 }, 12, 12, "", + { RenderType.NONE }) { + + override fun onMousePress() { + Minecraft.getMinecraft().ingameGUI.chatGUI.clearChatMessages() + } + + override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { + super.drawButton(mc, mouseX, mouseY) + if (visible) { + if (hovered) GlStateManager.color(1f, 1f, 160f / 255f) + else GlStateManager.color(1f, 1f, 1f) + mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "delete.png")) + Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt index e72dbe1..b22673b 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt @@ -33,4 +33,4 @@ class ScreenshotButton : Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) } } -} +}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt index 8f73f2c..39455ae 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt @@ -1,12 +1,12 @@ package cc.woverflow.chatting.utils -import club.sk1er.patcher.config.PatcherConfig -import com.llamalad7.betterchat.BetterChat import cc.woverflow.chatting.Chatting.isBetterChat import cc.woverflow.chatting.Chatting.isPatcher import cc.woverflow.chatting.config.ChattingConfig.textRenderType import cc.woverflow.chatting.hook.GuiNewChatHook import cc.woverflow.onecore.utils.drawBorderedString +import club.sk1er.patcher.config.PatcherConfig +import com.llamalad7.betterchat.BetterChat import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer @@ -35,12 +35,8 @@ object ModCompatHooks { @JvmStatic fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int { return when (textRenderType) { - 0 -> { - fontRenderer.drawString(text, x, y, color, false) - } - 2 -> { - fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) - } + 0 -> fontRenderer.drawString(text, x, y, color, false) + 2 -> fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) else -> fontRenderer.drawString(text, x, y, color, true) } } diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt index 393cc74..dc6a1e6 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt @@ -3,9 +3,17 @@ package cc.woverflow.chatting.utils import cc.woverflow.chatting.config.ChattingConfig +import cc.woverflow.chatting.mixin.GuiNewChatAccessor +import cc.woverflow.chatting.utils.ModCompatHooks.fontRenderer +import gg.essential.universal.UMouse +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine +import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.shader.Framebuffer +import net.minecraft.util.ChatComponentText +import net.minecraft.util.MathHelper import org.apache.commons.lang3.SystemUtils import org.lwjgl.BufferUtils import org.lwjgl.opengl.GL11 @@ -19,7 +27,10 @@ import java.lang.reflect.Field import java.lang.reflect.Method import java.nio.ByteBuffer import java.nio.ByteOrder +import java.text.SimpleDateFormat +import java.util.* import javax.imageio.ImageIO +import kotlin.math.roundToInt /** * Taken from https://github.com/Moulberry/HyChat @@ -206,4 +217,40 @@ fun Framebuffer.screenshot(file: File): BufferedImage { } } return bufferedimage +} + +private val sdf: SimpleDateFormat = SimpleDateFormat("HH:mm:ss") + +@JvmField +val messages: Map<ChatLine, Long> = mutableMapOf() +var lastMessage: ChatLine? = null +fun showTimestamp() { + if (!ChattingConfig.showTimestamp) return + val chatLine = getChatLineOverMouse(UMouse.getTrueX().roundToInt(), UMouse.getTrueY().roundToInt()) + if (chatLine != null) { + val long = messages[chatLine] + if (long != null) chatLine.chatComponent.appendText(" §7[${sdf.format(Date(long))}]§r") + } + val long = messages[lastMessage] + if (long != null) lastMessage?.chatComponent?.siblings?.remove(ChatComponentText(" §7[${sdf.format(Date(long))}]§r")) + lastMessage = chatLine +} + +private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? { + val chat = Minecraft.getMinecraft().ingameGUI.chatGUI + if (!chat.chatOpen) return null + val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) + val i = scaledResolution.scaleFactor + val f = chat.chatScale + val j = MathHelper.floor_float((mouseX / i - 3).toFloat() / f) + val k = MathHelper.floor_float((mouseY / i - 27).toFloat() / f) + if (j < 0 || k < 0) return null + val drawnChatLines = (chat as GuiNewChatAccessor).drawnChatLines + val l = chat.lineCount.coerceAtMost(drawnChatLines.size) + if (j <= MathHelper.floor_float(chat.chatWidth.toFloat() / f) && k < fontRenderer.FONT_HEIGHT * l + l) { + val m = k / Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + chat.scrollPos + if (m >= 0 && m < drawnChatLines.size) + return drawnChatLines[m] + } + return null }
\ No newline at end of file |