Class NbtMetadataStorage

java.lang.Object
io.artificial.enchantments.internal.NbtMetadataStorage

public class NbtMetadataStorage extends Object
Handles auxiliary metadata storage in NBT for items.

This class is strictly for auxiliary data (display markers, compatibility flags, custom data) and must NEVER store enchantment state. Native ItemMeta is the sole source of truth for enchantment levels and presence.

All metadata is stored under a root compound key to avoid collisions with other plugins or Minecraft's native data.

This class is thread-safe for read operations. Write operations should be synchronized at a higher level to ensure atomic item updates.

Since:
0.1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new NBT metadata storage handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull org.bukkit.inventory.ItemStack
    clear(@NotNull org.bukkit.inventory.ItemStack item)
    Clears all auxiliary metadata while preserving the root compound.
    boolean
    getBoolean(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, boolean defaultValue)
    Gets a boolean metadata value.
    int
    getInt(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, int defaultValue)
    Gets an integer metadata value.
    @NotNull Set<String>
    getKeys(@NotNull org.bukkit.inventory.ItemStack item)
    Gets all metadata keys.
    @Nullable String
    getString(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key)
    Gets a string metadata value.
    boolean
    hasAnyMetadata(@NotNull org.bukkit.inventory.ItemStack item)
    Checks if any auxiliary metadata exists.
    boolean
    hasKey(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key)
    Checks if a metadata key exists.
    @NotNull org.bukkit.inventory.ItemStack
    remove(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key)
    Removes a metadata entry.
    @NotNull org.bukkit.inventory.ItemStack
    setBoolean(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, boolean value)
    Sets a boolean metadata value.
    @NotNull org.bukkit.inventory.ItemStack
    setInt(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, int value)
    Sets an integer metadata value.
    @NotNull org.bukkit.inventory.ItemStack
    setString(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, @Nullable String value)
    Sets a string metadata value.

    Methods inherited from class java.lang.Object

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

    • NbtMetadataStorage

      public NbtMetadataStorage()
      Creates a new NBT metadata storage handler.
      Since:
      0.1.0
  • Method Details

    • setString

      @NotNull public @NotNull org.bukkit.inventory.ItemStack setString(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key, @Nullable @Nullable String value)
      Sets a string metadata value.
      Parameters:
      item - the item to modify
      key - the metadata key
      value - the value to store, or null to remove
      Returns:
      the modified item
    • getString

      @Nullable public @Nullable String getString(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key)
      Gets a string metadata value.
      Parameters:
      item - the item to query
      key - the metadata key
      Returns:
      the stored value, or null if not present
    • setInt

      @NotNull public @NotNull org.bukkit.inventory.ItemStack setInt(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key, int value)
      Sets an integer metadata value.
      Parameters:
      item - the item to modify
      key - the metadata key
      value - the value to store
      Returns:
      the modified item
    • getInt

      public int getInt(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key, int defaultValue)
      Gets an integer metadata value.
      Parameters:
      item - the item to query
      key - the metadata key
      defaultValue - the default value if not present
      Returns:
      the stored value, or defaultValue if not present
    • setBoolean

      @NotNull public @NotNull org.bukkit.inventory.ItemStack setBoolean(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key, boolean value)
      Sets a boolean metadata value.
      Parameters:
      item - the item to modify
      key - the metadata key
      value - the value to store
      Returns:
      the modified item
    • getBoolean

      public boolean getBoolean(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key, boolean defaultValue)
      Gets a boolean metadata value.
      Parameters:
      item - the item to query
      key - the metadata key
      defaultValue - the default value if not present
      Returns:
      the stored value, or defaultValue if not present
    • remove

      @NotNull public @NotNull org.bukkit.inventory.ItemStack remove(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key)
      Removes a metadata entry.
      Parameters:
      item - the item to modify
      key - the metadata key to remove
      Returns:
      the modified item
    • hasKey

      public boolean hasKey(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String key)
      Checks if a metadata key exists.
      Parameters:
      item - the item to query
      key - the metadata key
      Returns:
      true if the key exists
    • getKeys

      @NotNull public @NotNull Set<String> getKeys(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Gets all metadata keys.
      Parameters:
      item - the item to query
      Returns:
      an unmodifiable set of keys (may be empty)
    • clear

      @NotNull public @NotNull org.bukkit.inventory.ItemStack clear(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Clears all auxiliary metadata while preserving the root compound.
      Parameters:
      item - the item to modify
      Returns:
      the modified item
    • hasAnyMetadata

      public boolean hasAnyMetadata(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Checks if any auxiliary metadata exists.
      Parameters:
      item - the item to query
      Returns:
      true if any metadata keys exist