类 MetadataStoreBase<T>
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明disambiguate(T subject, @NotNull String metadataKey) 通过组合对象的唯一数据和metadataKey, 为接收元数据的对象创建唯一名称.getMetadata(T subject, @NotNull String metadataKey) 返回附加到对象的所有元数据值.booleanhasMetadata(T subject, @NotNull String metadataKey) 测试对象上是否设置了元数据属性.voidinvalidateAll(@NotNull Plugin owningPlugin) 使元数据存储中所有来自指定插件的元数据失效.void从对象中移除指定插件拥有的元数据项.voidsetMetadata(T subject, @NotNull String metadataKey, @NotNull MetadataValue newMetadataValue) 向对象添加元数据值.
-
构造器详细资料
-
MetadataStoreBase
public MetadataStoreBase()
-
-
方法详细资料
-
setMetadata
public void setMetadata(@NotNull T subject, @NotNull @NotNull String metadataKey, @NotNull @NotNull MetadataValue newMetadataValue) 向对象添加元数据值. 每个元数据值由特定Plugin拥有. 如果插件已经向对象添加了元数据值, 该值将被newMetadataValue的值替换. 多个插件可以为相同的metadataKey设置独立的值而不会冲突.实现说明:我考虑使用
ReadWriteLock来控制对metadataMap的访问, 但认为增加的开销不值得更细粒度的访问控制.Bukkit几乎完全是单线程的, 所以锁定开销应该不会造成问题.
原文: 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 ofnewMetadataValue. Multiple plugins can set independent values for the samemetadataKeywithout conflict.Implementation note: I considered using a
ReadWriteLockfor 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.
- 参数:
subject- 接收元数据的对象.metadataKey- 用于标识此元数据的唯一键.newMetadataValue- 要应用的元数据值.- 抛出:
IllegalArgumentException- 如果值为null, 或拥有插件为null- 另请参阅:
-
getMetadata
@NotNull public @NotNull List<MetadataValue> getMetadata(@NotNull T subject, @NotNull @NotNull String metadataKey) 返回附加到对象的所有元数据值. 如果多个插件附加了元数据, 每个值都将被包含.原文: Returns all metadata values attached to an object. If multiple have attached metadata, each will value will be included.
- 参数:
subject- 正在查询的对象.metadataKey- 正在查找的唯一元数据键.- 返回:
- 值列表, 每个设置了请求值的插件一个.
- 另请参阅:
-
hasMetadata
测试对象上是否设置了元数据属性.原文: Tests to see if a metadata attribute has been set on an object.
- 参数:
subject- 执行has-metadata测试的对象.metadataKey- 正在查询的唯一元数据键.- 返回:
- metadataKey在主体中的存在性.
-
removeMetadata
public void removeMetadata(@NotNull T subject, @NotNull @NotNull String metadataKey, @NotNull @NotNull Plugin owningPlugin) 从对象中移除指定插件拥有的元数据项.原文: Removes a metadata item owned by a plugin from a subject.
- 参数:
subject- 要移除元数据的对象.metadataKey- 用于标识要移除的元数据的唯一键.owningPlugin- 尝试移除元数据项的插件.- 抛出:
IllegalArgumentException- 如果插件为null- 另请参阅:
-
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.
- 参数:
owningPlugin- 请求失效的插件.- 抛出:
IllegalArgumentException- 如果插件为null- 另请参阅:
-
disambiguate
@NotNull protected abstract @NotNull String disambiguate(@NotNull T subject, @NotNull @NotNull String metadataKey) 通过组合对象的唯一数据和metadataKey, 为接收元数据的对象创建唯一名称.创建的名称对于给定对象必须是全局唯一的, 任何两个等价的对象必须生成相同的唯一名称. 例如, 如果两个Player对象代表同一个玩家, 即使这两个对象无法通过引用相等性测试, 它们也必须生成相同的字符串.
原文: 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.
- 参数:
subject- 为此对象生成键.metadataKey- 标识元数据值的名称.- 返回:
- 给定对象的唯一元数据键.
-