Package cn.nukkit.metadata
Class LazyMetadataValue
java.lang.Object
cn.nukkit.metadata.MetadataValue
cn.nukkit.metadata.MetadataValueAdapter
cn.nukkit.metadata.LazyMetadataValue
- Direct Known Subclasses:
FixedMetadataValue
The LazyMetadataValue class implements a type of metadata that is not
computed until another plugin asks for it.
By making metadata values lazy, no computation is done by the providing
plugin until absolutely necessary (if ever). Additionally,
LazyMetadataValue objects cache their values internally unless overridden
by a LazyMetadataValue.CacheStrategy
or invalidated at the individual or plugin
level. Once invalidated, the LazyMetadataValue will recompute its value
when asked.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Describes possible caching strategies for metadata. -
Field Summary
Fields inherited from class cn.nukkit.metadata.MetadataValue
owningPlugin
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
LazyMetadataValue
(Plugin owningPlugin) Protected special constructor used by FixedMetadataValue to bypass standard setup.LazyMetadataValue
(Plugin owningPlugin, LazyMetadataValue.CacheStrategy cacheStrategy, Callable<Object> lazyValue) Initializes a LazyMetadataValue object with a specific cache strategy.LazyMetadataValue
(Plugin owningPlugin, Callable<Object> lazyValue) Initialized a LazyMetadataValue object with the default CACHE_AFTER_FIRST_EVAL cache strategy. -
Method Summary
Methods inherited from class cn.nukkit.metadata.MetadataValueAdapter
asBoolean, asByte, asDouble, asFloat, asInt, asLong, asShort, asString, getOwningPlugin
-
Constructor Details
-
LazyMetadataValue
Initialized a LazyMetadataValue object with the default CACHE_AFTER_FIRST_EVAL cache strategy.- Parameters:
owningPlugin
- thePlugin
that created this metadata value.lazyValue
- the lazy value assigned to this metadata value.
-
LazyMetadataValue
public LazyMetadataValue(Plugin owningPlugin, LazyMetadataValue.CacheStrategy cacheStrategy, Callable<Object> lazyValue) Initializes a LazyMetadataValue object with a specific cache strategy.- Parameters:
owningPlugin
- thePlugin
that created this metadata value.cacheStrategy
- determines the rules for caching this metadata value.lazyValue
- the lazy value assigned to this metadata value.
-
LazyMetadataValue
Protected special constructor used by FixedMetadataValue to bypass standard setup.
-
-
Method Details
-
value
- Specified by:
value
in classMetadataValue
-
invalidate
public void invalidate()- Specified by:
invalidate
in classMetadataValue
-