Package org.bukkit.metadata
Class MetadataStoreBase<T>
java.lang.Object
org.bukkit.metadata.MetadataStoreBase<T>
public abstract class MetadataStoreBase<T> extends Object
-
Constructor Summary
Constructors Constructor Description MetadataStoreBase()
-
Method Summary
Modifier and Type Method Description protected abstract String
disambiguate(T subject, String metadataKey)
Creates a unique name for the object receiving metadata by combining unique data from the subject with a metadataKey.List<MetadataValue>
getMetadata(T subject, String metadataKey)
Returns all metadata values attached to an object.boolean
hasMetadata(T subject, String metadataKey)
Tests to see if a metadata attribute has been set on an object.void
invalidateAll(Plugin owningPlugin)
Invalidates all metadata in the metadata store that originates from the given plugin.void
removeMetadata(T subject, String metadataKey, Plugin owningPlugin)
Removes a metadata item owned by a plugin from a subject.void
setMetadata(T subject, String metadataKey, MetadataValue newMetadataValue)
Adds a metadata value to an object.
-
Constructor Details
-
MetadataStoreBase
public MetadataStoreBase()
-
-
Method Details
-
setMetadata
public void setMetadata(@NotNull T subject, @NotNull String metadataKey, @NotNull MetadataValue newMetadataValue)Adds a metadata value to an object. Each metadata value is owned by a specificPlugin
. If a plugin has already added a metadata value to an object, that value will be replaced with the value ofnewMetadataValue
. Multiple plugins can set independent values for the samemetadataKey
without conflict.Implementation note: I considered using a
ReadWriteLock
for controlling access tometadataMap
, but decided that the added overhead wasn't worth the finer grained access control.Bukkit is almost entirely single threaded so locking overhead shouldn't pose a problem.
- Parameters:
subject
- The object receiving the metadata.metadataKey
- A unique key to identify this metadata.newMetadataValue
- The metadata value to apply.- Throws:
IllegalArgumentException
- If value is null, or the owning plugin is null- See Also:
MetadataStore.setMetadata(Object, String, MetadataValue)
-
getMetadata
Returns all metadata values attached to an object. If multiple have attached metadata, each will value will be included.- Parameters:
subject
- the object being interrogated.metadataKey
- the unique metadata key being sought.- Returns:
- A list of values, one for each plugin that has set the requested value.
- See Also:
MetadataStore.getMetadata(Object, String)
-
hasMetadata
Tests to see if a metadata attribute has been set on an object.- Parameters:
subject
- the object upon which the has-metadata test is performed.metadataKey
- the unique metadata key being queried.- Returns:
- the existence of the metadataKey within subject.
-
removeMetadata
public void removeMetadata(@NotNull T subject, @NotNull String metadataKey, @NotNull Plugin owningPlugin)Removes a metadata item owned by a plugin from a subject.- Parameters:
subject
- the object to remove the metadata from.metadataKey
- the unique metadata key identifying the metadata to remove.owningPlugin
- the plugin attempting to remove a metadata item.- Throws:
IllegalArgumentException
- If plugin is null- See Also:
MetadataStore.removeMetadata(Object, String, org.bukkit.plugin.Plugin)
-
invalidateAll
Invalidates all metadata in the metadata store that originates from the given plugin. Doing this will force each invalidated metadata item to be recalculated the next time it is accessed.- Parameters:
owningPlugin
- the plugin requesting the invalidation.- Throws:
IllegalArgumentException
- If plugin is null- See Also:
MetadataStore.invalidateAll(org.bukkit.plugin.Plugin)
-
disambiguate
Creates a unique name for the object receiving metadata by combining unique data from the subject with a metadataKey.The name created must be globally unique for the given object and any two equivalent objects must generate the same unique name. For example, two Player objects must generate the same string if they represent the same player, even if the objects would fail a reference equality test.
- Parameters:
subject
- The object for which this key is being generated.metadataKey
- The name identifying the metadata value.- Returns:
- a unique metadata key for the given subject.
-