Class PacketBlockPlayerData
java.lang.Object
net.bitbylogic.packetblocks.block.PacketBlockPlayerData
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMetadata
(@NonNull String key, @NonNull Object object) Adds a metadata entry with the specified key and object.getMetadata
(@NonNull String key) Retrieves the metadata associated with the specified key.getMetadata
(@NonNull String key, @Nullable Object fallback) Retrieves the metadata associated with the given key.<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.boolean
hasMetadata
(@NonNull String key) Checks if a metadata entry with the specified key exists.void
removeMetadata
(@NonNull String key) Removes metadata associated with the specified key from the metadata map.
-
Constructor Details
-
PacketBlockPlayerData
public PacketBlockPlayerData()
-
-
Method Details
-
addMetadata
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 nullobject
- the object to be associated with the key; must not be null
-
removeMetadata
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
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
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
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 nullclazz
- 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
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.
-