Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<CustomRules> optional = this.customRules.stream().filter(rule -> rule.match(player, minecraftMessage)).findFirst();
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/modules/chat/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down