Interface MetadataHolder

All Known Subinterfaces:
PacketBlockHolder<T,V>
All Known Implementing Classes:
GroupPacketBlockViewer, PacketBlock, PacketBlockGroup, PacketBlockPlayerData, PacketBlockViewer, SinglePacketBlockViewer

public interface MetadataHolder
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addMetadata(@NonNull String key, @NonNull Object object)
    Adds a metadata entry with the specified key and object.
    default Object
    getMetadata(@NonNull String key)
    Retrieves the metadata associated with the specified key.
    default Object
    getMetadata(@NonNull String key, @Nullable Object fallback)
    Retrieves the metadata associated with the given key.
    default <T> T
    getMetadataAs(@NonNull String key, @NonNull Class<T> clazz)
    Retrieves the metadata associated with the given key and casts it to the specified type.
     
    default boolean
    hasMetadata(@NonNull String key)
    Checks if a metadata entry with the specified key exists.
    default void
    removeMetadata(@NonNull String key)
    Removes metadata associated with the specified key from the metadata map.
  • Method Details

    • getMetadataHandler

      @NonNull @NonNull MetadataHandler getMetadataHandler()
    • addMetadata

      default void addMetadata(@NonNull @NonNull String key, @NonNull @NonNull Object object)
      Adds a metadata entry with the specified key and object. If the key already exists in the metadata map, the method does nothing.
      Parameters:
      key - the key used to identify the metadata entry; must not be null
      object - the object to be associated with the key; must not be null
    • removeMetadata

      default void removeMetadata(@NonNull @NonNull String key)
      Removes metadata associated with the specified key from the metadata map.
      Parameters:
      key - the key whose associated metadata is to be removed. Must not be null.
    • hasMetadata

      default boolean hasMetadata(@NonNull @NonNull String key)
      Checks if a metadata entry with the specified key exists.
      Parameters:
      key - the key to check for metadata presence, must not be null
      Returns:
      true if metadata with the given key exists, false otherwise
    • getMetadata

      default Object getMetadata(@NonNull @NonNull String key)
      Retrieves the metadata associated with the specified key.
      Parameters:
      key - the key to look up in the metadata map; must not be null.
      Returns:
      the metadata value associated with the given key, or null if no value is present for the key.
    • getMetadataAs

      default <T> T getMetadataAs(@NonNull @NonNull String key, @NonNull @NonNull Class<T> clazz)
      Retrieves the metadata associated with the given key and casts it to the specified type.
      Parameters:
      key - the key for the metadata entry, must not be null
      clazz - the class type to cast the metadata value to, must not be null
      Returns:
      the metadata value associated with the provided key, cast to the desired type, or null if the key does not exist or the value could not be cast
      Throws:
      ClassCastException - if the metadata value cannot be cast to the specified type
    • getMetadata

      default Object getMetadata(@NonNull @NonNull String key, @Nullable @Nullable Object fallback)
      Retrieves the metadata associated with the given key. If no metadata exists for the key, returns the specified fallback value.
      Parameters:
      key - the key whose associated metadata is to be returned. Must not be null.
      fallback - the value to return if no metadata is found for the given key. May be null.
      Returns:
      the metadata associated with the specified key, or the fallback value if no metadata is found.