Skip to content

Commit

Permalink
fix: handle # correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rootEnginear committed Oct 15, 2023
1 parent 36ae7a6 commit 5c313f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@ 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()) {
instance.sendEncryptedChatToAllPlayers(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(
Expand All @@ -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)
);
}
}

0 comments on commit 5c313f4

Please sign in to comment.