Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.metadata.MetadataStoreBase< T > Class Template Referenceabstract

Public Member Functions

synchronized void setMetadata (T subject, String metadataKey, MetadataValue newMetadataValue)
 
synchronized List< MetadataValuegetMetadata (T subject, String metadataKey)
 
synchronized boolean hasMetadata (T subject, String metadataKey)
 
synchronized void removeMetadata (T subject, String metadataKey, Plugin owningPlugin)
 
synchronized void invalidateAll (Plugin owningPlugin)
 

Protected Member Functions

abstract String disambiguate (T subject, String metadataKey)
 

Detailed Description

Definition at line 8 of file MetadataStoreBase.java.

Member Function Documentation

abstract String org.bukkit.metadata.MetadataStoreBase< T >.disambiguate ( subject,
String  metadataKey 
)
abstractprotected

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
subjectThe object for which this key is being generated.
metadataKeyThe name identifying the metadata value.
Returns
a unique metadata key for the given subject.

Referenced by org.bukkit.metadata.MetadataStoreBase< String >.getMetadata(), org.bukkit.metadata.MetadataStoreBase< String >.hasMetadata(), org.bukkit.metadata.MetadataStoreBase< String >.removeMetadata(), and org.bukkit.metadata.MetadataStoreBase< String >.setMetadata().

synchronized List<MetadataValue> org.bukkit.metadata.MetadataStoreBase< T >.getMetadata ( subject,
String  metadataKey 
)

Returns all metadata values attached to an object. If multiple have attached metadata, each will value will be included.

Parameters
subjectthe object being interrogated.
metadataKeythe 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)

Definition at line 56 of file MetadataStoreBase.java.

56  {
57  String key = disambiguate(subject, metadataKey);
58  if (metadataMap.containsKey(key)) {
59  Collection<MetadataValue> values = metadataMap.get(key).values();
60  return Collections.unmodifiableList(new ArrayList<MetadataValue>(values));
61  } else {
62  return Collections.emptyList();
63  }
64  }
abstract String disambiguate(T subject, String metadataKey)
synchronized boolean org.bukkit.metadata.MetadataStoreBase< T >.hasMetadata ( subject,
String  metadataKey 
)

Tests to see if a metadata attribute has been set on an object.

Parameters
subjectthe object upon which the has-metadata test is performed.
metadataKeythe unique metadata key being queried.
Returns
the existence of the metadataKey within subject.

Definition at line 74 of file MetadataStoreBase.java.

74  {
75  String key = disambiguate(subject, metadataKey);
76  return metadataMap.containsKey(key);
77  }
abstract String disambiguate(T subject, String metadataKey)
synchronized void org.bukkit.metadata.MetadataStoreBase< T >.invalidateAll ( Plugin  owningPlugin)

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
owningPluginthe plugin requesting the invalidation.
See also
MetadataStore::invalidateAll(org.bukkit.plugin.Plugin)
Exceptions
IllegalArgumentExceptionIf plugin is null

Definition at line 113 of file MetadataStoreBase.java.

113  {
114  Validate.notNull(owningPlugin, "Plugin cannot be null");
115  for (Map<Plugin, MetadataValue> values : metadataMap.values()) {
116  if (values.containsKey(owningPlugin)) {
117  values.get(owningPlugin).invalidate();
118  }
119  }
120  }
synchronized void org.bukkit.metadata.MetadataStoreBase< T >.removeMetadata ( subject,
String  metadataKey,
Plugin  owningPlugin 
)

Removes a metadata item owned by a plugin from a subject.

Parameters
subjectthe object to remove the metadata from.
metadataKeythe unique metadata key identifying the metadata to remove.
owningPluginthe plugin attempting to remove a metadata item.
See also
MetadataStore::removeMetadata(Object, String, org.bukkit.plugin.Plugin)
Exceptions
IllegalArgumentExceptionIf plugin is null

Definition at line 90 of file MetadataStoreBase.java.

90  {
91  Validate.notNull(owningPlugin, "Plugin cannot be null");
92  String key = disambiguate(subject, metadataKey);
93  Map<Plugin, MetadataValue> entry = metadataMap.get(key);
94  if (entry == null) {
95  return;
96  }
97 
98  entry.remove(owningPlugin);
99  if (entry.isEmpty()) {
100  metadataMap.remove(key);
101  }
102  }
abstract String disambiguate(T subject, String metadataKey)
synchronized void org.bukkit.metadata.MetadataStoreBase< T >.setMetadata ( subject,
String  metadataKey,
MetadataValue  newMetadataValue 
)

Adds a metadata value to an object. Each metadata value is owned by a specific 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 java.util.concurrent.locks.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.

Parameters
subjectThe object receiving the metadata.
metadataKeyA unique key to identify this metadata.
newMetadataValueThe metadata value to apply.
See also
MetadataStore::setMetadata(Object, String, MetadataValue)
Exceptions
IllegalArgumentExceptionIf value is null, or the owning plugin is null

Definition at line 33 of file MetadataStoreBase.java.

33  {
34  Validate.notNull(newMetadataValue, "Value cannot be null");
35  Plugin owningPlugin = newMetadataValue.getOwningPlugin();
36  Validate.notNull(owningPlugin, "Plugin cannot be null");
37  String key = disambiguate(subject, metadataKey);
38  Map<Plugin, MetadataValue> entry = metadataMap.get(key);
39  if (entry == null) {
40  entry = new WeakHashMap<Plugin, MetadataValue>(1);
41  metadataMap.put(key, entry);
42  }
43  entry.put(owningPlugin, newMetadataValue);
44  }
abstract String disambiguate(T subject, String metadataKey)

The documentation for this class was generated from the following file: