aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
diff options
context:
space:
mode:
authorWyvest <wyvestbusiness@gmail.com>2023-11-23 19:07:22 +0900
committerWyvest <wyvestbusiness@gmail.com>2023-11-23 19:07:22 +0900
commit50dec3baa84ea72f9a711b936aabacf53aa04e05 (patch)
tree1f2840895ebf6934e2c1e9d78cfa3d963910b061 /src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
parent97a700fe1af0360b6deed3c6b0b0a3839d5a690d (diff)
downloadChatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.tar.gz
Chatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.tar.bz2
Chatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.zip
Various chat head bug fixes
- Fix chat heads making chat lines go over chat background - Fix chat heads making tooltip hovers not work properly
Diffstat (limited to 'src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java')
-rw-r--r--src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java91
1 files changed, 34 insertions, 57 deletions
diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
index 2e5f21c..cde09ea 100644
--- a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
+++ b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java
@@ -7,28 +7,23 @@ package org.polyfrost.chatting.mixin;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.hook.ChatLineHook;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
-import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.util.IChatComponent;
-import org.jetbrains.annotations.Nullable;
+import org.polyfrost.chatting.utils.ChatHeadHooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.lang.ref.WeakReference;
-import java.util.HashMap;
-import java.util.Map;
@Mixin(ChatLine.class)
public class ChatLineMixin implements ChatLineHook {
private boolean detected = false;
- private boolean first = true;
+ private boolean firstDetection = true;
private NetworkPlayerInfo playerInfo;
private NetworkPlayerInfo detectedPlayerInfo;
- private static NetworkPlayerInfo lastPlayerInfo;
private static long lastUniqueId = 0;
private long uniqueId = 0;
@@ -37,60 +32,17 @@ public class ChatLineMixin implements ChatLineHook {
lastUniqueId++;
uniqueId = lastUniqueId;
chatLines.add(new WeakReference<>((ChatLine) (Object) this));
- NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler();
- if (netHandler == null) return;
- Map<String, NetworkPlayerInfo> nicknameCache = new HashMap<>();
- try {
- for (String word : iChatComponent.getFormattedText().split("(ยง.)|\\W")) {
- if (word.isEmpty()) continue;
- playerInfo = netHandler.getPlayerInfo(word);
- if (playerInfo == null) {
- playerInfo = getPlayerFromNickname(word, netHandler, nicknameCache);
- }
- if (playerInfo != null) {
- detectedPlayerInfo = playerInfo;
- detected = true;
- if (playerInfo == lastPlayerInfo) {
- first = false;
- if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages()) {
- playerInfo = null;
- }
- } else {
- lastPlayerInfo = playerInfo;
- }
- break;
- }
- }
- } catch (Exception ignored) {
- }
+ ChatHeadHooks.INSTANCE.detect(iChatComponent.getFormattedText(), (ChatLine) (Object) this);
}
- @Nullable
- private static NetworkPlayerInfo getPlayerFromNickname(String word, NetHandlerPlayClient connection, Map<String, NetworkPlayerInfo> nicknameCache) {
- if (nicknameCache.isEmpty()) {
- for (NetworkPlayerInfo p : connection.getPlayerInfoMap()) {
- IChatComponent displayName = p.getDisplayName();
- if (displayName != null) {
- String nickname = displayName.getUnformattedTextForChat();
- if (word.equals(nickname)) {
- nicknameCache.clear();
- return p;
- }
-
- nicknameCache.put(nickname, p);
- }
- }
- } else {
- // use prepared cache
- return nicknameCache.get(word);
- }
-
- return null;
+ @Override
+ public boolean isDetected() {
+ return detected;
}
@Override
- public boolean hasDetected() {
- return detected;
+ public void setDetected(boolean detected) {
+ this.detected = detected;
}
@Override
@@ -99,8 +51,33 @@ public class ChatLineMixin implements ChatLineHook {
}
@Override
+ public void setPlayerInfo(NetworkPlayerInfo playerInfo) {
+ this.playerInfo = playerInfo;
+ }
+
+ @Override
+ public NetworkPlayerInfo getDetectedPlayerInfo() {
+ return detectedPlayerInfo;
+ }
+
+ @Override
+ public void setDetectedPlayerInfo(NetworkPlayerInfo detectedPlayerInfo) {
+ this.detectedPlayerInfo = detectedPlayerInfo;
+ }
+
+ @Override
+ public boolean isFirstDetection() {
+ return firstDetection;
+ }
+
+ @Override
+ public void setFirstDetection(boolean firstDetection) {
+ this.firstDetection = firstDetection;
+ }
+
+ @Override
public void updatePlayerInfo() {
- if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages() && !first) {
+ if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages() && !firstDetection) {
playerInfo = null;
} else {
playerInfo = detectedPlayerInfo;