
This metadata implementation has the following features: - All metadata is lazy. Metadata values are not actually computed until another plugin requests them. Memory and CPU are conserved by not computing and storing unnecessary metadata values. - All metadata is cached. Once a metadata value is computed its value is cached in the metadata store to prevent further unnecessary computation. An invalidation mechanism is provided to flush the cache and force recompilation of metadata values. - All metadata is stored in basic data types. Convenience methods in the MetadataValue class allow for the conversion of metadata data types when possible. Restricting metadata to basic data types prevents the accidental linking of large object graphs into metadata. Metadata is persistent across the lifetime of the application and adding large object graphs would damage garbage collector performance. - Metadata access is thread safe. Care has been taken to protect the internal data structures and access them in a thread safe manner. - Metadata is exposed for all objects that descend from Entity, Block, and World. All Entity and World metadata is stored at the Server level and all Block metadata is stored at the World level. - Metadata is NOT keyed on references to original objects - instead metadata is keyed off of unique fields within those objects. Doing this allows metadata to exist for blocks that are in chunks not currently in memory. Additionally, Player objects are keyed off of player name so that Player metadata remains consistent between logins. - Metadata convenience methods have been added to all Entities, Players, Blocks, BlockStates, and World allowing direct access to an individual instance's metadata. - Players and OfflinePlayers share a single metadata store, allowing player metadata to be manipulated regardless of the player's current online status.
53 lines
2.0 KiB
Java
53 lines
2.0 KiB
Java
package org.bukkit.metadata;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import java.util.List;
|
|
|
|
public interface MetadataStore<T> {
|
|
/**
|
|
* Adds a metadata value to an object.
|
|
*
|
|
* @param subject The object receiving the metadata.
|
|
* @param metadataKey A unique key to identify this metadata.
|
|
* @param newMetadataValue The metadata value to apply.
|
|
*/
|
|
public void setMetadata(T subject, String metadataKey, MetadataValue newMetadataValue);
|
|
|
|
/**
|
|
* Returns all metadata values attached to an object. If multiple plugins have attached metadata, each will value
|
|
* will be included.
|
|
*
|
|
* @param subject the object being interrogated.
|
|
* @param metadataKey the unique metadata key being sought.
|
|
* @return A list of values, one for each plugin that has set the requested value.
|
|
*/
|
|
public List<MetadataValue> getMetadata(T subject, String metadataKey);
|
|
|
|
/**
|
|
* Tests to see if a metadata attribute has been set on an object.
|
|
*
|
|
* @param subject the object upon which the has-metadata test is performed.
|
|
* @param metadataKey the unique metadata key being queried.
|
|
* @return the existence of the metadataKey within subject.
|
|
*/
|
|
public boolean hasMetadata(T subject, String metadataKey);
|
|
|
|
/**
|
|
* Removes a metadata item owned by a plugin from a subject.
|
|
*
|
|
* @param subject the object to remove the metadata from.
|
|
* @param metadataKey the unique metadata key identifying the metadata to remove.
|
|
* @param owningPlugin the plugin attempting to remove a metadata item.
|
|
*/
|
|
public void removeMetadata(T subject, String metadataKey, 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.
|
|
*
|
|
* @param owningPlugin the plugin requesting the invalidation.
|
|
*/
|
|
public void invalidateAll(Plugin owningPlugin);
|
|
}
|