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.
This commit is contained in:
Allink 2023-05-20 04:26:11 +01:00
parent 55859b6b15
commit 12cfdfe31d
No known key found for this signature in database

View File

@ -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> 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> 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> component)
{
if (debug)
{
return this.debugComponent(component.get());
}
return "";
}
}