E
- The type of element within the valueV
- The type of Valuepublic interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
BaseValue
.
Usually every ValueProcessor will deal only with
Value
s associated with the key returned by getKey()
.Modifier and Type | Method and Description |
---|---|
Optional<V> |
getApiValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
Gets the actual
Value object wrapping around the underlying value
desired from the provided ValueContainer . |
org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> |
getKey()
Gets the associated
Key that this ValueProcessor
will handle. |
int |
getPriority()
Gets the priority of this processor.
|
Optional<E> |
getValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
Gets the underlying value as an
Optional . |
org.spongepowered.api.data.DataTransactionResult |
offerToStore(org.spongepowered.api.data.value.ValueContainer<?> container,
E value)
Offers the provided
BaseValue containing a value of the
appropriate value type of this ValueProcessor to offer
back to the ValueContainer . |
org.spongepowered.api.data.DataTransactionResult |
removeFrom(org.spongepowered.api.data.value.ValueContainer<?> container)
Attempts to remove the known keyed data associated with this
ValueProcessor from the provided ValueContainer . |
boolean |
supports(org.spongepowered.api.data.value.ValueContainer<?> container)
Checks if the provided
ValueContainer is compatible with the
value of data associated with this ValueProcessor . |
org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> getKey()
Key
that this ValueProcessor
will handle.int getPriority()
Key
can have
multiple ValueProcessor
s such that mods introducing
changes to the game can provide their own ValueProcessor
s
for specific cases. The notion is that the higher the priority, the
earlier the processor is used. If for any reason a processor's method
is returning an Optional.empty()
or
DataTransactionResult
with a failure, the next processor in
line will be used. By default, all Sponge processors are with a
priority of 100.Optional<E> getValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
Optional
. This is the direct
implementation of ValueContainer.get(Key)
. As well, since the
return type is Optional
, this method too is applicable for
ValueContainer.getOrNull(Key)
and
ValueContainer.getOrElse(Key, Object)
as they are simply
additional methods called from Optional.orElse(Object)
and
Optional.orElse(Object)
.
To truly understand the use of this method, the thought process
is that a ValueContainer
being mixed in to existing minecraft
classes will require a pseudo lookup of the Key
to associate to
a field belonging to provided ValueContainer
. Being that the
Value
is very specific, the only assumption of mixed in
implementations will have no room for extra possibilities. Therefor,
this method serves as a "guarantee" that we've found the type of
Value
we want to retrieve, and all we need to do is validate
that the Value
is infact compatible with the provided
ValueContainer
.
An example of this type of interaction is getting the health from an
Entity
. Normally, when you have an Entity
, you can
grab health two ways:
entity.get(Keys.HEALTH)
entity.get(HealthData.class).health()
ValueContainer.get(Key)
will result in a call to this method for a
ValueProcessor
handling specifically the health value. The
second case will use the same ValueProcessor
but be retrieving
the values directly from the HealthData
DataManipulator
.
This differs with object creation as the second method will result in an
unecessary DataManipulator
to be created, and then finally a
ValueProcessor
method call for the DataManipulator
instead of the Entity
having a direct call.
The cases where this type of value usage is not preferable is with
more complex Value
s, such as CollectionValue
,
values found for MobSpawnerData
and CommandData
. Using
the ValueContainer.get(Key)
and
DataManipulator.set(Key, Object)
remains to be the optimal methods
to use as they do not rely on the implementation attempting to guess which
Key
, Value
and ValueProcessor
is needed to
manipulate the data.
container
- The value container to retrieve the value fromsOptional<V> getApiValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
Value
object wrapping around the underlying value
desired from the provided ValueContainer
. This is very similar to
getValueFromContainer(ValueContainer)
except that instead of an
actual value, a Value
or extension there of is returned.container
- The container to get the API value fromValue
typed valueboolean supports(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueContainer
is compatible with the
value of data associated with this ValueProcessor
.container
- The value container to checkorg.spongepowered.api.data.DataTransactionResult offerToStore(org.spongepowered.api.data.value.ValueContainer<?> container, E value)
BaseValue
containing a value of the
appropriate value type of this ValueProcessor
to offer
back to the ValueContainer
.container
- The value containervalue
- The valueorg.spongepowered.api.data.DataTransactionResult removeFrom(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
from the provided ValueContainer
. If
the result is not possible, the result will be an expected
DataTransactionResult.Type#FAILURE
.container
- The value container to remove data from