From 1c2620840f6f360537da66d6f562294b06c2d82c Mon Sep 17 00:00:00 2001 From: Draycia Date: Mon, 4 May 2020 09:00:21 -0700 Subject: [PATCH] Add more component support to Player --- .../net/minestom/server/entity/Player.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 7c1c9f1eb..a88b29c40 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -406,10 +406,7 @@ public class Player extends LivingEntity { } public void sendMessage(Component textObject) { - sendMessageJson(Chat.toJsonString(textObject)); - } - - private void sendMessageJson(String json) { + String json = Chat.toJsonString(textObject); playerConnection.sendPacket(new ChatMessagePacket(json, ChatMessagePacket.Position.CHAT)); } @@ -450,24 +447,31 @@ public class Player extends LivingEntity { playerConnection.sendPacket(stopSoundPacket); } - public void sendHeaderFooter(String header, String footer, char colorChar) { + public void sendHeaderFooter(Component header, Component footer) { PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket(); playerListHeaderAndFooterPacket.emptyHeader = header == null; playerListHeaderAndFooterPacket.emptyFooter = footer == null; - - playerListHeaderAndFooterPacket.header = Chat.toJsonString(Chat.fromLegacyText(header, colorChar)); - playerListHeaderAndFooterPacket.footer = Chat.toJsonString(Chat.fromLegacyText(footer, colorChar)); + playerListHeaderAndFooterPacket.header = Chat.toJsonString(header); + playerListHeaderAndFooterPacket.footer = Chat.toJsonString(footer); playerConnection.sendPacket(playerListHeaderAndFooterPacket); } - public void sendActionBarMessage(String message, char colorChar) { + public void sendHeaderFooter(String header, String footer, char colorChar) { + sendHeaderFooter(Chat.fromLegacyText(header, colorChar), Chat.fromLegacyText(footer, colorChar)); + } + + public void sendActionBarMessage(Component message) { TitlePacket titlePacket = new TitlePacket(); titlePacket.action = TitlePacket.Action.SET_ACTION_BAR; - titlePacket.actionBarText = Chat.toJsonString(Chat.fromLegacyText(message, colorChar)); + titlePacket.actionBarText = Chat.toJsonString(message); playerConnection.sendPacket(titlePacket); } + public void sendActionBarMessage(String message, char colorChar) { + sendActionBarMessage(Chat.fromLegacyText(message, colorChar)); + } + public void sendActionBarMessage(String message) { sendActionBarMessage(message, Chat.COLOR_CHAR); }