diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-03 23:36:44 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-03 23:36:44 +0200 |
commit | a4c61672d93aaf7418568ca6b3704289d890f48b (patch) | |
tree | 7418d0531f9f35ddef449fb44ec272a14ad9bc8a /src/main/java/at/hannibal2 | |
parent | 75ad1cd4a13487932750913b7c3054146adfd50e (diff) | |
download | skyhanni-a4c61672d93aaf7418568ca6b3704289d890f48b.tar.gz skyhanni-a4c61672d93aaf7418568ca6b3704289d890f48b.tar.bz2 skyhanni-a4c61672d93aaf7418568ca6b3704289d890f48b.zip |
code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt | 18 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt | 16 |
2 files changed, 13 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index 167efdb3b..8b6330f6d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -23,7 +23,6 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.ReflectionHelper import java.lang.invoke.MethodHandles -import java.util.LinkedHashMap object ChatManager { @@ -39,9 +38,7 @@ object ChatManager { } } - fun getRecentMessageHistory(): List<MessageFilteringResult> { - return messageHistory.toList().map { it.second } - } + fun getRecentMessageHistory(): List<MessageFilteringResult> = messageHistory.toList().map { it.second } enum class ActionKind(format: Any) { BLOCKED(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD), @@ -154,7 +151,7 @@ object ChatManager { } fun openChatFilterGUI() { - SkyHanniMod.screenToOpen = (ChatFilterGui(getRecentMessageHistory())) + SkyHanniMod.screenToOpen = ChatFilterGui(getRecentMessageHistory()) } val chatLinesField by lazy { @@ -167,12 +164,13 @@ object ChatManager { fun retractMessage(message: IChatComponent?, reason: String) { if (message == null) return val chatGUI = Minecraft.getMinecraft().ingameGUI.chatGUI + @Suppress("UNCHECKED_CAST") val chatLines = chatLinesField.invokeExact(chatGUI) as MutableList<ChatLine> - if (chatLines.removeIf { it.chatComponent === message }) { - val history = messageHistory[IdentityCharacteristics(message)] - history?.actionKind = ActionKind.RETRACTED - history?.actionReason = reason.uppercase() - } + if (!chatLines.removeIf { it.chatComponent === message }) return chatGUI.refreshChat() + + val history = messageHistory[IdentityCharacteristics(message)] ?: return + history.actionKind = ActionKind.RETRACTED + history.actionReason = reason.uppercase() } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt index 8f346ddea..971878306 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt @@ -11,7 +11,6 @@ import net.minecraft.client.gui.GuiUtilRenderComponents import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.IChatComponent -import org.lwjgl.input.Keyboard import org.lwjgl.input.Mouse class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult>) : GuiScreen() { @@ -31,23 +30,18 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult GlStateManager.pushMatrix() val l = (width / 2.0 - w / 2.0).toInt() val t = (height / 2.0 - h / 2.0).toInt() - val sr = ScaledResolution(mc) GlStateManager.translate(l + 0.0, t + 0.0, 0.0) RenderUtils.drawFloatingRectDark(0, 0, w, h) GlStateManager.translate(5.0, 5.0 - scroll, 0.0) - var mouseX = mouseX - (l) - val isMouseButtonDown = if (mouseX in 0..w && mouseY in t..(t + h)) - Mouse.isButtonDown(0) - else false + var mouseX = mouseX - l + val isMouseButtonDown = if (mouseX in 0..w && mouseY in t..(t + h)) Mouse.isButtonDown(0) else false var mouseY = mouseY - (t - scroll).toInt() - GlStateManager.color(1f, 1f, 1f, 1f) + val sr = ScaledResolution(mc) GlScissorStack.push(l + 5, t + 5, w + l - 5, h + t - 5, sr) for (msg in history) { drawString(mc.fontRendererObj, msg.actionKind.renderedString, 0, 0, -1) - GlStateManager.color(1f, 1f, 1f, 1f) drawString(mc.fontRendererObj, msg.actionReason, ChatManager.ActionKind.maxLength + 5, 0, -1) - GlStateManager.color(1f, 1f, 1f, 1f) var size = drawMultiLineText( msg.message, ChatManager.ActionKind.maxLength + reasonMaxLength + 10, @@ -77,9 +71,10 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult GlScissorStack.pop(sr) wasMouseButtonDown = isMouseButtonDown GlStateManager.popMatrix() + GlStateManager.color(1f, 1f, 1f, 1f) } - fun splitLine(comp: IChatComponent): MutableList<IChatComponent> { + fun splitLine(comp: IChatComponent): List<IChatComponent> { return GuiUtilRenderComponents.splitText( comp, w - (ChatManager.ActionKind.maxLength + reasonMaxLength + 10 + 10), @@ -110,7 +105,6 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult 0, -1 ) - GlStateManager.color(1f, 1f, 1f, 1f) GlStateManager.translate(0F, 10F, 0F) } return modifiedSplitText.size |