Class MetadataHolder

java.lang.Object
net.mathias2246.buildmc.api.event.MetadataHolder

public abstract class MetadataHolder extends Object
Base class providing metadata support for custom events.

Metadata allows additional context to be stored and shared with plugins without needing to subclass the event. Each entry is a key-value pair. Keys must be unique within a single event 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 associated with this event.

      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

      protected 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 event's metadata directly.

      Returns:
      the mutable map of metadata entries (never null)
    • 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 the event.

      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