mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 16:41:35 +01:00
Merge pull request #198 from BomBardyGamer/master
Vanilla formatted chat messages
This commit is contained in:
commit
62b78f70d7
@ -1,7 +1,9 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -12,6 +14,7 @@ import net.minestom.server.network.packet.server.play.ChatMessagePacket;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ChatMessageListener {
|
||||
@ -66,11 +69,19 @@ public class ChatMessageListener {
|
||||
|
||||
private static Component buildDefaultChatMessage(PlayerChatEvent chatEvent) {
|
||||
final String username = chatEvent.getPlayer().getUsername();
|
||||
final UUID uuid = chatEvent.getPlayer().getUuid();
|
||||
|
||||
return Component.text("<" + username + ">")
|
||||
.hoverEvent(Component.text("Click to send a message to " + username))
|
||||
.clickEvent(ClickEvent.suggestCommand("/msg " + username + " "))
|
||||
.append(Component.text(" " + chatEvent.getMessage()));
|
||||
return Component.translatable("chat.type.text")
|
||||
.args(Component.text(username)
|
||||
.insertion(username)
|
||||
.clickEvent(ClickEvent.suggestCommand("/msg" + username))
|
||||
.hoverEvent(HoverEvent.showEntity(HoverEvent.ShowEntity.of(
|
||||
Key.key("minecraft", "player"),
|
||||
uuid,
|
||||
Component.text(username)
|
||||
))),
|
||||
Component.text(chatEvent.getMessage())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user