From 12cfdfe31d4e58e56b2da399747d14bfa0a6301e Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 20 May 2023 04:26:11 +0100 Subject: [PATCH] Add methods specifically for logging components to FreedomLogger The new component-logging methods are ALL suffixed with "Component" to prevent type erasure conflicts with the other Supplier methods. These methods were added for completeness for when I make the FreedomLogger an Audience. --- .../me/totalfreedom/utils/FreedomLogger.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java index c0deaa1..219a2e5 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java @@ -36,6 +36,20 @@ public class FreedomLogger logger.info(message); } + /** + * This method allows you to log a component to the console. + * + * @param component The component to send. + * @return A plain text representation of the message + */ + public String infoComponent(Component component) + { + String plainText = FreedomAdventure.toPlainText(component); + + logger.info(plainText); + return plainText; + } + /** * This method allows you to log a message to the console, * while also returning a Component that could be used to @@ -50,6 +64,19 @@ public class FreedomLogger return Component.text(message.get()); } + /** + * This method allows you to log a component to the console, + * while also returning a String representation of the + * component + * + * @param component The component to send. + * @return A string representation of the message. + */ + public String infoComponent(Supplier component) + { + return this.infoComponent(component.get()); + } + /** * This method allows you to log a warning to the console. * @@ -60,6 +87,18 @@ public class FreedomLogger logger.warn(message); } + /** + * This method allows you to log a warning to the console. + * + * @param component The component to send. + */ + public void warnComponent(Component component) + { + String plainText = FreedomAdventure.toPlainText(component); + + logger.warn(plainText); + } + /** * This method logs an error message to the console. * It is highly recommended to deconstruct the stack trace and pass it @@ -72,6 +111,20 @@ public class FreedomLogger logger.error(message); } + /** + * This method logs an error component to the console. + * + * @param component The message to send. + */ + public String errorComponent(Component component) + { + String plainText = FreedomAdventure.toPlainText(component); + + logger.error(plainText); + + return plainText; + } + /** * This method allows you to log an exception directly to the console. * @@ -98,6 +151,19 @@ public class FreedomLogger return Component.text(message.get()); } + /** + * This method allows you to log an error component to the console, + * while also returning a String representation of the error + * component. + * + * @param component The component to send. + * @return A String representation of the component. + */ + public String errorComponent(Supplier component) + { + return this.errorComponent(component.get()); + } + /** * This method allows you to log a debug message to the console. * This method will only log if debug mode is enabled. @@ -110,6 +176,21 @@ public class FreedomLogger logger.debug(message); } + /** + * This method allows you to log a debug component to the console. + * This method will only log if debug mode is enabled. + * + * @param component The component to send. + */ + public String debugComponent(Component component) + { + String plainText = FreedomAdventure.toPlainText(component); + + this.debug(plainText); + + return plainText; + } + /** * This method allows you to log a debug message to the console, * while also returning a Component that could be used to @@ -128,4 +209,21 @@ public class FreedomLogger } return Component.empty(); } + + /** + * This method allows you to log a debug component to the console, + * while also returning a String representation of the debug component. + * + * @param component The component to send. + * @return A String representation of the message. + */ + public String debugComponent(Supplier component) + { + if (debug) + { + return this.debugComponent(component.get()); + } + return ""; + } + }