Class ItemStackUtils
java.lang.Object
com.ultikits.ultitools.utils.ItemStackUtils
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable org.bukkit.inventory.ItemStackdeserializeItem(@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 booleanisLegacy(byte[] bytes) static booleanisValidSerialized(@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 StringserializeItem(@Nullable org.bukkit.inventory.ItemStack item) Serializes a single ItemStack to a Base64-encoded string.static @Nullable StringserializeItems(@Nullable org.bukkit.inventory.ItemStack @Nullable [] items) Serializes an array using Paper's item byte format and Base64 encoding.
-
Field Details
-
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:
IOExceptionClassNotFoundException
-
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
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
-