From 98d1a21aab86d6026767152c8e1a7717034583f7 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 17 Jun 2023 10:56:58 +0200 Subject: [PATCH] sendChatMessage() for online players --- .../standalone/AbstractOnlinePlayer.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pandalib-players/src/main/java/fr/pandacube/lib/players/standalone/AbstractOnlinePlayer.java b/pandalib-players/src/main/java/fr/pandacube/lib/players/standalone/AbstractOnlinePlayer.java index 2370b16..ea26cc9 100644 --- a/pandalib-players/src/main/java/fr/pandacube/lib/players/standalone/AbstractOnlinePlayer.java +++ b/pandalib-players/src/main/java/fr/pandacube/lib/players/standalone/AbstractOnlinePlayer.java @@ -72,18 +72,31 @@ public interface AbstractOnlinePlayer extends AbstractOffPlayer { */ /** - * Display the provided message in the player’s chat, if the chat is activated. + * Display the provided message in the player’s chat, if SYSTEM messages are activated. * @param message the message to display. */ void sendMessage(Component message); /** - * Display the provided message in the player’s chat, if the chat is activated. + * Display the provided message in the player’s chat, if SYSTEM messages are activated. * @param message the message to display. */ default void sendMessage(ComponentLike message) { sendMessage(message.asComponent()); } + + /** + * Display the provided message in the player’s chat, if CHAT messages are activated on the client. + *

+ * This method differs from {@link #sendMessage(ComponentLike)} with the fact that this method sends the message + * only if {@link #canChat()} returns true. + * The message sent to the client is still a SYSTEM messge, due to CHAT messages required to be signed. + * @param message the message to display as CHAT message. + */ + default void sendChatMessage(ComponentLike message) { + if (canChat()) + sendMessage(message.asComponent()); + } /** * Display the provided message in the player’s chat, if the chat is activated, prepended with the server prefix.