From 2fd2008f6510408fb94aebdb32b69c56efa73298 Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 20 May 2023 04:31:18 +0100 Subject: [PATCH] Make the FreedomLogger an Audience This will allow for a FreedomLogger instance to be added to any collection of audiences. This was written for usage in a future TransactionSpy implementation. --- .../me/totalfreedom/utils/FreedomLogger.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java index 219a2e5..6172443 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java @@ -1,12 +1,17 @@ package me.totalfreedom.utils; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.function.Supplier; -public class FreedomLogger +public class FreedomLogger implements Audience { private final Logger logger; private boolean debug = false; @@ -226,4 +231,42 @@ public class FreedomLogger return ""; } + + @Override + public void sendMessage(@NotNull ComponentLike message) + { + Component component = ComponentLike.unbox(message); + + if (component == null) + { + this.info("**null component-like**"); + return; + } + + this.infoComponent(component); + } + + @Override + public void sendMessage(@NotNull Component message) + { + this.infoComponent(message); + } + + @Override + public void sendMessage(@NotNull Component message, ChatType.@NotNull Bound boundChatType) + { + this.infoComponent(message); + } + + @Override + public void sendMessage(@NotNull ComponentLike message, ChatType.@NotNull Bound boundChatType) + { + this.sendMessage(message); + } + + @Override + public void sendMessage(@NotNull SignedMessage signedMessage, ChatType.@NotNull Bound boundChatType) + { + this.info(signedMessage.message()); // TODO: We might want to investigate whether this logs the ENTIRE message, including unsigned & signed content, or only the signed part. This method was written in the assumption that it provided all content. + } }