Interface Component


public interface Component
This interface is used to encapsulate the components used by nChat.

Creating an instance from a Minecraft component: Use the from(Object) method to turn it into an nChat component.

Creating a Minecraft component from an instance: Use the to(Component, Class) method to turn it into a Minecraft component.

  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a clone of this component's instance.
    Returns the native component encapsulated by nChat.
    static Component
    from(Object minecraftComponent)
    Converts Minecraft components to nChat components.
    Gets the content of this component.
    static <T> T
    to(Component component, Class<T> minecraftComponentClass)
    Converts nChat components to Minecraft components.
    default <T> T
    to(Class<T> minecraftComponentClass)
    Converts nChat components to Minecraft components.
  • Method Details

    • text

      String text()
      Gets the content of this component.
      Returns:
      the content of this component (contain legacy colors)
    • clone

      Component clone()
      Creates a clone of this component's instance.
      Returns:
      another instance of this component.
    • component

      Object component()
      Returns the native component encapsulated by nChat.

      Supported libraries:

      • adventure Component
      • md_5 TextComponent
      Returns:
      the Minecraft component
    • to

      default <T> T to(Class<T> minecraftComponentClass)
      Converts nChat components to Minecraft components.

      Supported libraries:

      • adventure Component
      • md_5 TextComponent
      Parameters:
      minecraftComponentClass - the Minecraft component class
      Returns:
      the Minecraft component
      Throws:
      IllegalArgumentException - if the supplied component class is not supported
    • to

      static <T> T to(Component component, Class<T> minecraftComponentClass) throws IllegalArgumentException
      Converts nChat components to Minecraft components.

      Supported libraries:

      • adventure Component
      • md_5 TextComponent
      Parameters:
      component - the value of the nChat component
      minecraftComponentClass - the Minecraft component class
      Returns:
      the Minecraft component
      Throws:
      IllegalArgumentException - if the supplied component class is not supported
    • from

      static Component from(Object minecraftComponent) throws IllegalArgumentException
      Converts Minecraft components to nChat components.

      Supported libraries:

      • adventure Component
      • md_5 TextComponent
      Parameters:
      minecraftComponent - the Minecraft component
      Returns:
      the value of the nChat component
      Throws:
      IllegalArgumentException - if the supplied component is not supported