Class VersionedComponentUtil

java.lang.Object
com.kamikazejam.kamicommon.nms.util.VersionedComponentUtil

public class VersionedComponentUtil extends Object
Utility for interacting with VersionedComponent and various server apis.

This provider selects the appropriate VersionedComponent implementation based on the current Minecraft version, handling the evolution of the adventure api and its integration natively into paper.

See Also:
  • Constructor Details

    • VersionedComponentUtil

      public VersionedComponentUtil()
  • Method Details

    • serializer

      @NotNull public static @NotNull VersionedComponentSerializer serializer()
      Mirror method to
      invalid reference
      NmsAPI#getVersionedComponentSerializer()
      for convenience.
    • setDisplayName

      @NotNull public static @NotNull ItemMeta setDisplayName(@NotNull @NotNull ItemMeta meta, @Nullable @Nullable VersionedComponent component)
      Set the display name of an item stack using a VersionedComponent.

      On older versions the component is serialized to legacy codes, while on newer versions it uses the native adventure api.
      Returns:
      the same ItemMeta instance (for chaining).
    • setLore

      @NotNull public static @NotNull ItemMeta setLore(@NotNull @NotNull ItemMeta meta, @Nullable @Nullable List<VersionedComponent> lore)
      Set the lore of an item stack using a list of VersionedComponents.

      On older versions the components are serialized to legacy codes, while on newer versions it uses the native adventure api.
      Parameters:
      meta - the item meta to modify
      lore - the lore lines as versioned components, or null to remove lore
      Returns:
      the same ItemMeta instance (for chaining).
    • getLore

      @Nullable public static @Nullable List<VersionedComponent> getLore(@NotNull @NotNull ItemMeta meta)
      Get the lore of an item stack as a list of VersionedComponents.

      Returns null if the item has no lore.
      Parameters:
      meta - the item meta to read from
      Returns:
      the lore lines as versioned components, or null if no lore
    • getDisplayName

      @Nullable public static @Nullable VersionedComponent getDisplayName(@NotNull @NotNull ItemMeta meta)
      Get the display name of an item stack as a VersionedComponent.

      Returns null if the item has no custom display name.
      Parameters:
      meta - the item meta to read from
      Returns:
      the display name as a versioned component, or null if no custom name
    • addLoreLine

      @NotNull public static @NotNull ItemMeta addLoreLine(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull VersionedComponent component)
      Add a single line to the lore of an item stack using a VersionedComponent.

      If the item has no existing lore, creates a new lore list with this component.
      Parameters:
      meta - the item meta to modify
      component - the lore line to add
      Returns:
      the same ItemMeta instance (for chaining).