public abstract class MetadataStoreBase<T>
extends java.lang.Object
Constructor | Description |
---|---|
MetadataStoreBase() |
Modifier and Type | Method | Description |
---|---|---|
protected abstract java.lang.String |
disambiguate(T subject,
java.lang.String metadataKey) |
Creates a unique name for the object receiving metadata by combining
unique data from the subject with a metadataKey.
|
java.util.List<MetadataValue> |
getMetadata(T subject,
java.lang.String metadataKey) |
Returns all metadata values attached to an object.
|
boolean |
hasMetadata(T subject,
java.lang.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,
java.lang.String metadataKey,
Plugin owningPlugin) |
Removes a metadata item owned by a plugin from a subject.
|
void |
setMetadata(T subject,
java.lang.String metadataKey,
MetadataValue newMetadataValue) |
Adds a metadata value to an object.
|
public void setMetadata(T subject, java.lang.String metadataKey, MetadataValue newMetadataValue)
Plugin
. If a plugin has already added a metadata value
to an object, that value will be replaced with the value of
newMetadataValue
. Multiple plugins can set independent values for the
same metadataKey
without conflict.
Implementation note: I considered using a ReadWriteLock
for controlling access to
metadataMap
, 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.
subject
- The object receiving the metadata.metadataKey
- A unique key to identify this metadata.newMetadataValue
- The metadata value to apply.java.lang.IllegalArgumentException
- If value is null, or the owning plugin
is nullMetadataStore.setMetadata(Object, String, MetadataValue)
public java.util.List<MetadataValue> getMetadata(T subject, java.lang.String metadataKey)
subject
- the object being interrogated.metadataKey
- the unique metadata key being sought.MetadataStore.getMetadata(Object, String)
public boolean hasMetadata(T subject, java.lang.String metadataKey)
subject
- the object upon which the has-metadata test is
performed.metadataKey
- the unique metadata key being queried.public void removeMetadata(T subject, java.lang.String metadataKey, Plugin owningPlugin)
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.java.lang.IllegalArgumentException
- If plugin is nullMetadataStore.removeMetadata(Object, String,
org.bukkit.plugin.Plugin)
public void invalidateAll(Plugin owningPlugin)
owningPlugin
- the plugin requesting the invalidation.java.lang.IllegalArgumentException
- If plugin is nullMetadataStore.invalidateAll(org.bukkit.plugin.Plugin)
protected abstract java.lang.String disambiguate(T subject, java.lang.String 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.
subject
- The object for which this key is being generated.metadataKey
- The name identifying the metadata value.Copyright © 2018. All rights reserved.