Class NbtMetadataStorage
java.lang.Object
io.artificial.enchantments.internal.NbtMetadataStorage
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 -
Method Summary
Modifier and TypeMethodDescription@NotNull org.bukkit.inventory.ItemStackclear(@NotNull org.bukkit.inventory.ItemStack item) Clears all auxiliary metadata while preserving the root compound.booleangetBoolean(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, boolean defaultValue) Gets a boolean metadata value.intGets an integer metadata value.getKeys(@NotNull org.bukkit.inventory.ItemStack item) Gets all metadata keys.@Nullable StringGets a string metadata value.booleanhasAnyMetadata(@NotNull org.bukkit.inventory.ItemStack item) Checks if any auxiliary metadata exists.booleanChecks if a metadata key exists.@NotNull org.bukkit.inventory.ItemStackRemoves a metadata entry.@NotNull org.bukkit.inventory.ItemStacksetBoolean(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, boolean value) Sets a boolean metadata value.@NotNull org.bukkit.inventory.ItemStackSets an integer metadata value.@NotNull org.bukkit.inventory.ItemStacksetString(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String key, @Nullable String value) Sets a string metadata value.
-
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 modifykey- the metadata keyvalue- 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 querykey- 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 modifykey- the metadata keyvalue- 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 querykey- the metadata keydefaultValue- 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 modifykey- the metadata keyvalue- 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 querykey- the metadata keydefaultValue- 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 modifykey- 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 querykey- the metadata key- Returns:
- true if the key exists
-
getKeys
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
-