diff --git a/.gitignore b/.gitignore index 184060e8a6..7db56facac 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,10 @@ classes/ .gradle/ .architectury-transformer/ -# Data generated while running Minecraft +# Data generated while running Minecraft or tests run/ .devauth/microsoft_accounts.json +*/logs/* # IDEs .idea/ diff --git a/common/src/main/java/com/wynntils/handlers/chat/ChatHandler.java b/common/src/main/java/com/wynntils/handlers/chat/ChatHandler.java index d5b3b8602b..d0b8cdbe75 100644 --- a/common/src/main/java/com/wynntils/handlers/chat/ChatHandler.java +++ b/common/src/main/java/com/wynntils/handlers/chat/ChatHandler.java @@ -8,6 +8,7 @@ import com.wynntils.core.components.Handler; import com.wynntils.core.components.Managers; import com.wynntils.core.consumers.features.Feature; +import com.wynntils.core.mod.event.WynncraftConnectionEvent; import com.wynntils.core.text.StyledText; import com.wynntils.handlers.chat.event.ChatMessageReceivedEvent; import com.wynntils.handlers.chat.event.NpcDialogEvent; @@ -104,6 +105,18 @@ public void removeNpcDialogExtractionDependent(Feature feature) { dialogExtractionDependents.remove(feature); } + @SubscribeEvent + public void onConnectionChange(WynncraftConnectionEvent event) { + // Reset chat handler + collectedLines = new ArrayList<>(); + chatScreenTicks = 0; + lastRealChat = null; + lastSlowdownApplied = 0; + lastScreenNpcDialog = List.of(); + delayedDialogue = null; + delayedType = NpcDialogueType.NONE; + } + @SubscribeEvent public void onTick(TickEvent event) { if (collectedLines.isEmpty()) return; @@ -349,9 +362,12 @@ private void handleScreenNpcDialog(List dialog, boolean isSelection) private void handleFakeChatLine(Component message) { // This is a normal, single line chat, sent in the background StyledText styledText = StyledText.fromComponent(message); + if (styledText.isEmpty()) return; - // But it can weirdly enough actually also be a foreground NPC chat message... - if (getRecipientType(styledText, MessageType.FOREGROUND) == RecipientType.NPC) { + // But it can weirdly enough actually also be a foreground NPC chat message, or + // a game message; similar to a dialogue but not uttered by an NPC. + RecipientType recipientType = getRecipientType(styledText, MessageType.FOREGROUND); + if (recipientType == RecipientType.NPC || recipientType == RecipientType.GAME_MESSAGE) { // In this case, do *not* save this as last chat, since it will soon disappear // from history! postNpcDialogue(List.of(message), NpcDialogueType.CONFIRMATIONLESS, false); @@ -383,7 +399,7 @@ private Component postChatLine(Component message, StyledText styledText, Message WynntilsMod.info("[CHAT] " + styledText.getString().replace("§", "&")); RecipientType recipientType = getRecipientType(styledText, messageType); - if (recipientType == RecipientType.NPC) { + if (recipientType == RecipientType.NPC || recipientType == RecipientType.GAME_MESSAGE) { if (shouldSeparateNPC()) { postNpcDialogue(List.of(message), NpcDialogueType.CONFIRMATIONLESS, false); // We need to cancel the original chat event, if any diff --git a/common/src/main/java/com/wynntils/handlers/chat/type/RecipientType.java b/common/src/main/java/com/wynntils/handlers/chat/type/RecipientType.java index 25c21db5b7..66c6f87407 100644 --- a/common/src/main/java/com/wynntils/handlers/chat/type/RecipientType.java +++ b/common/src/main/java/com/wynntils/handlers/chat/type/RecipientType.java @@ -24,7 +24,8 @@ public enum RecipientType { PARTY("^§7\\[§e[^➤]*§7\\] §f.*$", "^(§8)?\\[§7[^➤]*§8\\] §7[^§]*$", "Party"), PRIVATE("^§7\\[.* ➤ .*\\] §f.*$", "^(§8)?\\[.* ➤ .*\\] §7.*$", "Private"), SHOUT("^§5.* \\[[A-Z0-9]+\\] shouts: §d.*$", "^(§8)?.* \\[[A-Z0-9]+\\] shouts: §7.*$", "Shout"), - PETS("^§2(.*): §a(.*)$", "^§8(.*): §7(.*)$", "Pets"); + PETS("^§2(.*): §a(.*)$", "^§8(.*): §7(.*)$", "Pets"), + GAME_MESSAGE("^§7[A-Z0-9].*$", null, "Game Message"); // Like dialogues but not uttered by an NPC private final Pattern foregroundPattern; private final Pattern backgroundPattern;