feat: add warning notification when no players hear local chat
This commit is contained in:
@@ -45,6 +45,7 @@ public class ChatHandler {
|
||||
.append(sender.getDisplayName());
|
||||
|
||||
if (text.startsWith(prefix)) {
|
||||
// ГЛОБАЛЬНИЙ ЧАТ
|
||||
String actualMessage = text.substring(1).trim();
|
||||
Component globalMessage = Component.empty()
|
||||
.append(formattedName)
|
||||
@@ -55,15 +56,33 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
} else {
|
||||
Component localMessage = Component.empty()
|
||||
.append(formattedName)
|
||||
.append(Component.literal(": " + text).withStyle(ChatFormatting.GRAY));
|
||||
// ЛОКАЛЬНИЙ ЧАТ
|
||||
int heardCount = 0;
|
||||
|
||||
for (ServerPlayer player : players) {
|
||||
if (player.level() == serverLevel && player.distanceTo(sender) <= LOCAL_CHAT_RADIUS) {
|
||||
player.sendSystemMessage(localMessage);
|
||||
if (player != sender) {
|
||||
heardCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (heardCount > 0) {
|
||||
Component localMessage = Component.empty()
|
||||
.append(formattedName)
|
||||
.append(Component.literal(": " + text).withStyle(ChatFormatting.GRAY));
|
||||
|
||||
for (ServerPlayer player : players) {
|
||||
if (player.level() == serverLevel && player.distanceTo(sender) <= LOCAL_CHAT_RADIUS) {
|
||||
player.sendSystemMessage(localMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendSystemMessage(
|
||||
Component.literal("Вас ніхто не почув, додайте на початок повідомлення \"!\" аби написати в глобальний чат")
|
||||
.withStyle(ChatFormatting.ITALIC, ChatFormatting.YELLOW)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user