Class Converters

java.lang.Object
com.comphenix.protocol.wrappers.Converters

public class Converters extends Object
Utility class for converters
Author:
dmulloy2
  • Constructor Details

    • Converters

      public Converters()
  • Method Details

    • ignoreNull

      public static <T> EquivalentConverter<T> ignoreNull(EquivalentConverter<T> converter)
      Returns a converter that ignores null elements, so that the underlying converter doesn't have to worry about them.
      Type Parameters:
      T - Element type
      Parameters:
      converter - Underlying converter
      Returns:
      An ignore null converter
    • passthrough

      public static <T> EquivalentConverter<T> passthrough(Class<T> clazz)
      Returns a converter that passes generic and specific values through without converting.
      Type Parameters:
      T - Element type
      Parameters:
      clazz - Element class
      Returns:
      A passthrough converter
    • handle

      public static <T> EquivalentConverter<T> handle(Function<T,​Object> toHandle, Function<Object,​T> fromHandle, Class<T> specificType)
      Creates a simple converter for wrappers with getHandle() and fromHandle(...) methods. With Java 8, converters can be reduced to a single line (see BukkitConverters.getWrappedGameProfileConverter()).
      Type Parameters:
      T - Wrapper type
      Parameters:
      toHandle - Function from wrapper to handle (i.e. getHandle())
      fromHandle - Function from handle to wrapper (i.e. fromHandle(Object))
      Returns:
      A handle converter
    • array

      public static <T> EquivalentConverter<T[]> array(Class<?> nmsClass, EquivalentConverter<T> converter)
      Creates a generic array converter. Converts a NMS object array to and from a wrapper array by converting each element individually.
      Type Parameters:
      T - Generic type
      Parameters:
      nmsClass - NMS class
      converter - Underlying converter
      Returns:
      An array converter
    • optional

      public static <T> EquivalentConverter<Optional<T>> optional(EquivalentConverter<T> converter)