From a4c61672d93aaf7418568ca6b3704289d890f48b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 3 Aug 2023 23:36:44 +0200 Subject: code cleanup --- .../java/at/hannibal2/skyhanni/data/ChatManager.kt | 18 ++++++++---------- .../hannibal2/skyhanni/features/chat/ChatFilterGui.kt | 16 +++++----------- 2 files changed, 13 insertions(+), 21 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') 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 { - return messageHistory.toList().map { it.second } - } + fun getRecentMessageHistory(): List = 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 - 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) : GuiScreen() { @@ -31,23 +30,18 @@ class ChatFilterGui(private val history: List { + fun splitLine(comp: IChatComponent): List { return GuiUtilRenderComponents.splitText( comp, w - (ChatManager.ActionKind.maxLength + reasonMaxLength + 10 + 10), @@ -110,7 +105,6 @@ class ChatFilterGui(private val history: List