Class TemporaryMinecraftComponentSerializer

java.lang.Object
net.citizensnpcs.api.util.TemporaryMinecraftComponentSerializer
All Implemented Interfaces:
net.kyori.adventure.text.serializer.ComponentDecoder<Object,net.kyori.adventure.text.Component>, net.kyori.adventure.text.serializer.ComponentEncoder<net.kyori.adventure.text.Component,Object>, net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component,Object>

@Experimental public final class TemporaryMinecraftComponentSerializer extends Object implements net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component,Object>
A component serializer for net.minecraft.server.<version>.IChatBaseComponent.

Due to Bukkit version namespaces, the return type does not reflect the actual type.

Color downsampling will be performed as necessary for the running server version.

If not isSupported(), an UnsupportedOperationException will be thrown on any serialize or deserialize operations.

Since:
4.0.0
See Also:
  • Constructor Details

    • TemporaryMinecraftComponentSerializer

      public TemporaryMinecraftComponentSerializer()
  • Method Details

    • deserialize

      @NotNull public @NotNull net.kyori.adventure.text.Component deserialize(@NotNull @NotNull Object input)
      Specified by:
      deserialize in interface net.kyori.adventure.text.serializer.ComponentDecoder<Object,net.kyori.adventure.text.Component>
      Specified by:
      deserialize in interface net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component,Object>
    • serialize

      @NotNull public @NotNull Object serialize(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Specified by:
      serialize in interface net.kyori.adventure.text.serializer.ComponentEncoder<net.kyori.adventure.text.Component,Object>
      Specified by:
      serialize in interface net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component,Object>
    • findClass

      @Nullable public static @Nullable Class<?> findClass(@Nullable @Nullable String @NotNull ... classNames)
      Gets a class by the first name available.
      Parameters:
      classNames - an array of class names to try in order
      Returns:
      a class or null if not found
    • findConstructor

      @Nullable public static @Nullable MethodHandle findConstructor(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Class<?>... parameterClasses)
      Gets a handle for a class constructor.
      Parameters:
      holderClass - a class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • findCraftClass

      @Nullable public static @Nullable Class<?> findCraftClass(@NotNull @NotNull String className)
      Gets a org.bukkit.craftbukkit class.
      Parameters:
      className - a class name, without the org.bukkit.craftbukkit prefix
      Returns:
      a class or null if not found
    • findCraftClass

      @Nullable public static <T> @Nullable Class<? extends T> findCraftClass(@NotNull @NotNull String className, @NotNull @NotNull Class<T> superClass)
      Gets a org.bukkit.craftbukkit class.
      Type Parameters:
      T - a super type
      Parameters:
      className - a class name, without the org.bukkit.craftbukkit prefix
      superClass - a super class
      Returns:
      a class or null if not found
    • findCraftClassName

      @Nullable public static @Nullable String findCraftClassName(@NotNull @NotNull String className)
      Gets a org.bukkit.craftbukkit class name.
      Parameters:
      className - a class name, without the org.bukkit.craftbukkit prefix
      Returns:
      a class name or null if not found
    • findEnum

      @Nullable public static @Nullable Object findEnum(@Nullable @Nullable Class<?> enumClass, @NotNull @NotNull String enumName)
      Gets an enum value.
      Parameters:
      enumClass - an enum class
      enumName - an enum name
      Returns:
      an enum value or null if not found
    • findEnum

      @Nullable public static @Nullable Object findEnum(@Nullable @Nullable Class<?> enumClass, @NotNull @NotNull String enumName, int enumFallbackOrdinal)
      Gets an enum value.
      Parameters:
      enumClass - an enum class
      enumName - an enum name
      enumFallbackOrdinal - an enum ordinal, when the name is not found
      Returns:
      an enum value or null if not found
    • findField

      @Nullable public static @Nullable Field findField(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Class<?> expectedType, @NotNull @NotNull String... fieldNames)
      Gets a class field if it exists and is of the appropriate type and makes it accessible.
      Parameters:
      holderClass - a class
      expectedType - the expected type of the field
      fieldNames - a field name
      Returns:
      an accessible field
    • findField

      @Nullable public static @Nullable Field findField(@Nullable @Nullable Class<?> holderClass, @NotNull @NotNull String... fieldName)
      Gets a class field if possible and makes it accessible.
      Parameters:
      holderClass - a class
      fieldName - a field name
      Returns:
      an accessible field
    • findGetterOf

      @Nullable public static @Nullable MethodHandle findGetterOf(@Nullable @Nullable Field field)
      Return a method handle that can get the value of the provided field.
      Parameters:
      field - the field to get
      Returns:
      a handle, if accessible
    • findMcClass

      @Nullable public static @Nullable Class<?> findMcClass(@NotNull @NotNull String... classNames)
      Get a net.minecraft class.
      Parameters:
      classNames - a class name, without the net.minecraft prefix
      Returns:
      a class name or null if not found
    • findMcClassName

      @Nullable public static @Nullable String findMcClassName(@NotNull @NotNull String className)
      Gets a net.minecraft class name.
      Parameters:
      className - a class name, without the net.minecraft prefix
      Returns:
      a class name or null if not found
    • findMethod

      @Nullable public static @Nullable MethodHandle findMethod(@Nullable @Nullable Class<?> holderClass, String methodName, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Gets a handle for a class method.
      Parameters:
      holderClass - a class
      methodName - a method name
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • findMethod

      @Nullable public static @Nullable MethodHandle findMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable String @NotNull [] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Gets a handle for a class method.
      Parameters:
      holderClass - a class
      methodNames - a method name
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • findNmsClass

      @Nullable public static @Nullable Class<?> findNmsClass(@NotNull @NotNull String className)
      Get a net.minecraft.server class.
      Parameters:
      className - a class name, without the net.minecraft.server prefix
      Returns:
      a class name or null if not found
    • findNmsClassName

      @Nullable public static @Nullable String findNmsClassName(@NotNull @NotNull String className)
      Gets a net.minecraft.server class name.
      Parameters:
      className - a class name, without the net.minecraft.server prefix
      Returns:
      a class name or null if not found
    • findSetterOf

      @Nullable public static @Nullable MethodHandle findSetterOf(@Nullable @Nullable Field field)
      Return a method handle that can set the value of the provided field.
      Parameters:
      field - the field to set
      Returns:
      a handle, if accessible
    • findStaticMethod

      @Nullable public static @Nullable MethodHandle findStaticMethod(@Nullable @Nullable Class<?> holderClass, String methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Gets a handle for a class method.
      Parameters:
      holderClass - a class
      methodNames - a method name
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • findStaticMethod

      @Nullable public static @Nullable MethodHandle findStaticMethod(@Nullable @Nullable Class<?> holderClass, String[] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Gets a handle for a class method.
      Parameters:
      holderClass - a class
      methodNames - a method name
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • get

      @NotNull public static @NotNull TemporaryMinecraftComponentSerializer get()
      Gets the component serializer.
      Returns:
      a component serializer
      Since:
      4.0.0
    • hasClass

      public static boolean hasClass(@NotNull @NotNull String... classNames)
      Gets whether a class is available.
      Parameters:
      classNames - an array of class names to try in order
      Returns:
      if the class is loaded
    • hasField

      public static boolean hasField(@Nullable @Nullable Class<?> holderClass, Class<?> type, String... names)
      Gets whether a class has a method.
      Parameters:
      holderClass - a class
      type - the field type
      names - field name candidates, will be checked in order
      Returns:
      if the method exists
    • hasMethod

      public static boolean hasMethod(@Nullable @Nullable Class<?> holderClass, String methodName, Class<?>... parameterClasses)
      Gets whether a class has a method.
      Parameters:
      holderClass - a class
      methodName - a method name
      parameterClasses - an array of method parameter classes
      Returns:
      if the method exists
    • hasMethod

      public static boolean hasMethod(@Nullable @Nullable Class<?> holderClass, String[] methodNames, Class<?>... parameterClasses)
      Gets whether a class has a method.
      Parameters:
      holderClass - a class
      methodNames - a method name
      parameterClasses - an array of method parameter classes
      Returns:
      if the method exists
    • isCraftBukkit

      public static boolean isCraftBukkit()
      Gets whether CraftBukkit is available.
      Returns:
      if CraftBukkit is available
    • isSupported

      public static boolean isSupported()
      Gets whether this serializer is supported.
      Returns:
      if the serializer is supported.
      Since:
      4.0.0
    • lookup

      public static @NotNull MethodHandles.Lookup lookup()
      Gets the singleton method handle lookup.
      Returns:
      the method handle lookup
    • needClass

      @NotNull public static @NotNull Class<?> needClass(@Nullable @Nullable String @NotNull ... className)
      Gets a net.minecraft class.
      Parameters:
      className - a class name, without the net.minecraft prefix
      Returns:
      a class
      Throws:
      NullPointerException - if the class was not found
    • needCraftClass

      @NotNull public static @NotNull Class<?> needCraftClass(@NotNull @NotNull String className)
      Gets a org.bukkit.craftbukkit class.
      Parameters:
      className - a class name, without the org.bukkit.craftbukkit prefix
      Returns:
      a class
      Throws:
      NullPointerException - if the class was not found
    • needField

      @NotNull public static @NotNull Field needField(@NotNull @NotNull Class<?> holderClass, @NotNull @NotNull String fieldName) throws NoSuchFieldException
      Gets a class field and makes it accessible.
      Parameters:
      holderClass - a class
      fieldName - a field name
      Returns:
      an accessible field
      Throws:
      NoSuchFieldException - when thrown by Class.getDeclaredField(String)
    • needMcClass

      @NotNull public static @NotNull Class<?> needMcClass(@NotNull @NotNull String... className)
      Gets a net.minecraft class.
      Parameters:
      className - a class name, without the net.minecraft prefix
      Returns:
      a class
      Throws:
      NullPointerException - if the class was not found
    • needNmsClass

      @NotNull public static @NotNull Class<?> needNmsClass(@NotNull @NotNull String className)
      Gets a net.minecraft.server class.
      Parameters:
      className - a class name, without the org.bukkit.craftbukkit prefix
      Returns:
      a class
      Throws:
      NullPointerException - if the class was not found
    • searchMethod

      public static MethodHandle searchMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Integer modifier, String methodName, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Search a handle for a class method.
      Parameters:
      holderClass - a class
      modifier - method modifiers
      methodName - a method name
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found
    • searchMethod

      public static MethodHandle searchMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Integer modifier, @Nullable @Nullable String @NotNull [] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses)
      Search a handle for a class method.
      Parameters:
      holderClass - a class
      modifier - method modifiers
      methodNames - a method names
      returnClass - a method return class
      parameterClasses - an array of method parameter classes
      Returns:
      a method handle or null if not found