From 1ca6899f942f8a03711f9337dd219827ec64b472 Mon Sep 17 00:00:00 2001 From: Maxence Simon <32517160+Maxlego08@users.noreply.github.com> Date: Sat, 20 Dec 2025 12:33:34 +0100 Subject: [PATCH] Add configurable local and global chat handling --- .../essentials/module/modules/chat/ChatModule.java | 12 ++++++++++++ src/main/resources/modules/chat/config.yml | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/fr/maxlego08/essentials/module/modules/chat/ChatModule.java b/src/main/java/fr/maxlego08/essentials/module/modules/chat/ChatModule.java index 5288005c..fb1c54d2 100644 --- a/src/main/java/fr/maxlego08/essentials/module/modules/chat/ChatModule.java +++ b/src/main/java/fr/maxlego08/essentials/module/modules/chat/ChatModule.java @@ -93,6 +93,8 @@ public class ChatModule extends ZModule { private String playerPingColorOther; private float playerPingSoundVolume; private float playerPingSoundPitch; + private boolean enableLocalChat; + private double localChatDistance; public ChatModule(ZEssentialsPlugin plugin) { @@ -169,6 +171,12 @@ public void onTalk(AsyncChatEvent event) { } String message = PlainTextComponentSerializer.plainText().serialize(event.originalMessage()); + boolean isGlobalChat = false; + + if (this.enableLocalChat && message.startsWith("!")) { + isGlobalChat = true; + message = message.substring(1).stripLeading(); + } final String minecraftMessage = message; Optional optional = this.customRules.stream().filter(rule -> rule.match(player, minecraftMessage)).findFirst(); @@ -206,6 +214,10 @@ public void onTalk(AsyncChatEvent event) { } String finalMessage = message; + double maxDistanceSquared = this.localChatDistance * this.localChatDistance; + if (this.enableLocalChat && !isGlobalChat) { + event.viewers().removeIf(viewer -> viewer instanceof Player playerViewer && (!playerViewer.getWorld().equals(player.getWorld()) || playerViewer.getLocation().distanceSquared(player.getLocation()) > maxDistanceSquared)); + } event.renderer((source, sourceDisplayName, ignoredMessage, viewer) -> { String localMessage = finalMessage; diff --git a/src/main/resources/modules/chat/config.yml b/src/main/resources/modules/chat/config.yml index aefe3ad7..4f7874a3 100644 --- a/src/main/resources/modules/chat/config.yml +++ b/src/main/resources/modules/chat/config.yml @@ -47,6 +47,12 @@ enable-chat-dynamic-cooldown: true # Check player tries to put the same message multiple times enable-same-message-cancel: true +# Enables local chat where messages are only visible to nearby players unless prefixed with '!' +enable-local-chat: false + +# Maximum distance in blocks for local chat messages +local-chat-distance: 100 + # Apply a format to the chat, disabled on if you want another plugin to handle this enable-chat-format: true