From 5c313f427d107c6574b70c5a24ed3b6f0c39c79d Mon Sep 17 00:00:00 2001 From: rootEnginear Date: Sun, 15 Oct 2023 09:30:34 +0700 Subject: [PATCH] fix: handle `# ` correctly --- gradle.properties | 2 +- .../mixin/NetServerHandlerMixin.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7528a62..04ef631 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,6 @@ loader_version=0.14.19-babric.1-bta # halplibe_version=2.3.0 # Mod -mod_version=1.0.0 +mod_version=0.1.0 mod_group=rootenginear mod_name=proximitychat diff --git a/src/main/java/rootenginear/proximitychat/mixin/NetServerHandlerMixin.java b/src/main/java/rootenginear/proximitychat/mixin/NetServerHandlerMixin.java index f498477..a670658 100644 --- a/src/main/java/rootenginear/proximitychat/mixin/NetServerHandlerMixin.java +++ b/src/main/java/rootenginear/proximitychat/mixin/NetServerHandlerMixin.java @@ -28,7 +28,7 @@ public class NetServerHandlerMixin { ) ) private void proximityChat(ServerConfigurationManager instance, String s) { - Pattern playerChatPattern = Pattern.compile("<§.(.+?)§r> §0(.+)"); + Pattern playerChatPattern = Pattern.compile("<(.+?)> §0(.+)"); Matcher result = playerChatPattern.matcher(s); if (!result.matches()) { @@ -36,12 +36,20 @@ private void proximityChat(ServerConfigurationManager instance, String s) { return; } - String rawPlayerName = result.group(1); + String colorfulName = result.group(1); + String rawPlayerName = colorfulName.substring(0, colorfulName.length() - 2).substring(2); String msg = result.group(2); PlayerChannelConfig playerData = getPlayerChannelData(rawPlayerName); - if (playerData.isGlobal && !msg.startsWith("# ") || !playerData.isGlobal && msg.startsWith("# ")) { - instance.sendEncryptedChatToAllPlayers(s.replaceFirst("# ", "")); + boolean isGlobal = playerData.isGlobal; + + if (msg.startsWith("# ")) { + msg = msg.replaceFirst("# ", ""); + isGlobal = !isGlobal; + } + + if (isGlobal) { + instance.sendEncryptedChatToAllPlayers("<" + colorfulName + "> §0" + msg); return; } instance.sendPacketToPlayersAroundPoint( @@ -50,7 +58,7 @@ private void proximityChat(ServerConfigurationManager instance, String s) { this.playerEntity.z, playerData.radius, this.playerEntity.dimension, - new Packet3Chat("<✉ " + rawPlayerName + "> §0" + msg.replaceFirst("# ", "")) + new Packet3Chat("<⧈ " + colorfulName + "> §0" + msg) ); } }