Class TextComponentUtils

java.lang.Object
org.skriptlang.skript.bukkit.text.TextComponentUtils

public final class TextComponentUtils extends Object
Utilities for working with Components.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.kyori.adventure.text.Component
    appendToEnd(net.kyori.adventure.text.Component base, net.kyori.adventure.text.Component appendee)
     
    static @Nullable Expression<? extends net.kyori.adventure.text.Component>
    Attempts to convert an expression into one that is guaranteed to return a component.
    static net.kyori.adventure.text.Component
    from(Object message)
    Creates a component from an object.
    static net.kyori.adventure.text.Component
    joinByNewLine(net.kyori.adventure.text.Component... components)
    Joins components together with new line components.
    static String
    Replaces all legacy formatting codes in a string with MiniMessage equivalents.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • from

      public static net.kyori.adventure.text.Component from(Object message)
      Creates a component from an object.
      If message is a Component, message is simply returned.
      If message is a String, a safely-formatted Component (see TextComponentParser.parseSafe(Object)) is returned.
      Otherwise, a plain text component is returned.
      Parameters:
      message - The message to create a component from.
      Returns:
      A component from the given message.
    • joinByNewLine

      public static net.kyori.adventure.text.Component joinByNewLine(net.kyori.adventure.text.Component... components)
      Joins components together with new line components.
      Parameters:
      components - The components to join.
      Returns:
      A component representing the provided components joined by new line components.
      See Also:
      • Component.newline()
    • appendToEnd

      public static net.kyori.adventure.text.Component appendToEnd(net.kyori.adventure.text.Component base, net.kyori.adventure.text.Component appendee)
    • replaceLegacyFormattingCodes

      public static String replaceLegacyFormattingCodes(String text)
      Replaces all legacy formatting codes in a string with MiniMessage equivalents.
      Parameters:
      text - The string to reformat.
      Returns:
      Reformatted text.
    • asComponentExpression

      @Nullable public static @Nullable Expression<? extends net.kyori.adventure.text.Component> asComponentExpression(Expression<?> expression)
      Attempts to convert an expression into one that is guaranteed to return a component.
      Parameters:
      expression - The expression to convert.
      Returns:
      An expression that will wrap the output of expression in a Component. Will return null if expression is unable to be defended (see LiteralUtils.defendExpression(Expression)).