Class PacketBlockPlayerData

java.lang.Object
net.bitbylogic.packetblocks.block.PacketBlockPlayerData

public class PacketBlockPlayerData extends Object
  • Constructor Details

    • PacketBlockPlayerData

      public PacketBlockPlayerData()
  • Method Details

    • addMetadata

      public 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

      public 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

      public 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

      public 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

      public <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

      public 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.