Class MetadataHolder

java.lang.Object
net.mathias2246.buildmc.util.MetadataHolder
Direct Known Subclasses:
Team

public abstract class MetadataHolder extends Object
Base class providing metadata storage.

Metadata allows additional context to be stored and shared with plugins. Each entry is a key-value pair. Keys must be unique within a metadata holder instance.

This class provides an unmodifiable view for external access to prevent accidental modification of the internal state.

  • Constructor Details

    • MetadataHolder

      public MetadataHolder()
  • Method Details

    • getMetadata

      @NotNull public @NotNull Map<String,Object> getMetadata()
      Returns an unmodifiable view of all metadata entries stored in this instance.

      This map should not be modified directly; use putMetadata(String, Object) or removeMetadata(String) to update entries.

      Returns:
      an unmodifiable map containing all metadata (never null)
    • mutableMetadata

      @NotNull protected @NotNull Map<String,Object> mutableMetadata()
      Provides internal access to the mutable metadata map.

      Intended for subclasses or internal use only. Modifications to this map will affect the instance's metadata directly.

      Returns:
      the mutable map of metadata entries (never null)
    • containsMetadataKey

      @Contract(pure=true) public boolean containsMetadataKey(@NotNull @NotNull String key)
      Checks if a certain metadata key is present in this instance.
      Parameters:
      key - The key to check
      Returns:
      true if the given metadata key is present in this instance.
    • putMetadata

      public void putMetadata(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Adds a new metadata entry or updates the value for an existing key.
      Parameters:
      key - the metadata key (must not be null)
      value - the metadata value (must not be null)
      Throws:
      NullPointerException - if key or value is null
    • removeMetadata

      public void removeMetadata(@NotNull @NotNull String key)
      Removes a metadata entry from this instance.

      If the key does not exist, this method does nothing.

      Parameters:
      key - the metadata key to remove (must not be null)
      Throws:
      NullPointerException - if key is null