Class ItemStackUtils

java.lang.Object
com.ultikits.ultitools.utils.ItemStackUtils

public final class ItemStackUtils extends Object
Utility class for ItemStack serialization and deserialization. Uses Base64 encoding of Paper's item bytes for storage.
Since:
6.2.0
Version:
1.0.0
Author:
wisdomme
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Logger
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable org.bukkit.inventory.ItemStack
    deserializeItem(@Nullable String data)
    Deserializes a Base64-encoded string back to a single ItemStack.
    static @Nullable org.bukkit.inventory.ItemStack @Nullable []
    deserializeItems(@Nullable String data)
    Deserializes a Base64-encoded array of Paper item bytes, accepting MIME line breaks.
    private static boolean
    isLegacy(byte[] bytes)
     
    static boolean
    isValidSerialized(@Nullable String data)
    Checks whether a string can be deserialized as an item array.
    private static org.bukkit.inventory.ItemStack[]
    readLegacy(byte[] bytes)
     
    static @Nullable String
    serializeItem(@Nullable org.bukkit.inventory.ItemStack item)
    Serializes a single ItemStack to a Base64-encoded string.
    static @Nullable String
    serializeItems(@Nullable org.bukkit.inventory.ItemStack @Nullable [] items)
    Serializes an array using Paper's item byte format and Base64 encoding.

    Methods inherited from class Object

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

    • LOGGER

      private static final Logger LOGGER
  • Constructor Details

    • ItemStackUtils

      private ItemStackUtils()
  • Method Details

    • serializeItems

      @Nullable public static @Nullable String serializeItems(@Nullable @Nullable org.bukkit.inventory.ItemStack @Nullable [] items)
      Serializes an array using Paper's item byte format and Base64 encoding.
      Parameters:
      items - the array to serialize, including null or empty slots
      Returns:
      the Base64-encoded string, or null for null input or a serialization failure
    • deserializeItems

      @Nullable public static @Nullable org.bukkit.inventory.ItemStack @Nullable [] deserializeItems(@Nullable @Nullable String data)
      Deserializes a Base64-encoded array of Paper item bytes, accepting MIME line breaks. Empty items are returned as null slots. Legacy Bukkit object streams saved by 6.x are also accepted.
      Parameters:
      data - the Base64-encoded string
      Returns:
      the item array, or null for absent input or a deserialization failure
    • isLegacy

      private static boolean isLegacy(byte[] bytes)
    • readLegacy

      private static org.bukkit.inventory.ItemStack[] readLegacy(byte[] bytes) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • serializeItem

      @Nullable public static @Nullable String serializeItem(@Nullable @Nullable org.bukkit.inventory.ItemStack item)
      Serializes a single ItemStack to a Base64-encoded string.
      Parameters:
      item - the item to serialize
      Returns:
      the Base64-encoded string, or null for null input or a serialization failure
    • deserializeItem

      @Nullable public static @Nullable org.bukkit.inventory.ItemStack deserializeItem(@Nullable @Nullable String data)
      Deserializes a Base64-encoded string back to a single ItemStack.
      Parameters:
      data - the Base64-encoded string
      Returns:
      the first item, or null for a deserialization failure, empty array or empty slot
    • isValidSerialized

      public static boolean isValidSerialized(@Nullable @Nullable String data)
      Checks whether a string can be deserialized as an item array.
      Parameters:
      data - the Base64-encoded string to check
      Returns:
      true if the string can be deserialized, false otherwise