public abstract class AbstractSpongeValueProcessor<C,E,V extends org.spongepowered.api.data.value.BaseValue<E>> extends Object implements ValueProcessor<E,V>
Modifier | Constructor and Description |
---|---|
protected |
AbstractSpongeValueProcessor(Class<C> containerClass,
org.spongepowered.api.data.key.Key<V> key) |
Modifier and Type | Method and Description |
---|---|
protected abstract org.spongepowered.api.data.value.immutable.ImmutableValue<E> |
constructImmutableValue(E value) |
protected abstract V |
constructValue(E defaultValue)
Builds a
Value of the type produced by this processor from an
input, actual value. |
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.
|
protected abstract Optional<E> |
getVal(C container) |
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 . |
protected abstract boolean |
set(C container,
E value) |
protected boolean |
supports(C container) |
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 . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
removeFrom
protected abstract V constructValue(E defaultValue)
Value
of the type produced by this processor from an
input, actual value.defaultValue
- The actual valueValue
protected abstract org.spongepowered.api.data.value.immutable.ImmutableValue<E> constructImmutableValue(E value)
protected boolean supports(C container)
public boolean supports(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
ValueContainer
is compatible with the
value of data associated with this ValueProcessor
.supports
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
container
- The value container to checkpublic final org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> getKey()
ValueProcessor
Key
that this ValueProcessor
will handle.getKey
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
public int getPriority()
ValueProcessor
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.getPriority
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
public Optional<E> getValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
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.
getValueFromContainer
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
container
- The value container to retrieve the value fromspublic Optional<V> getApiValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
Value
object wrapping around the underlying value
desired from the provided ValueContainer
. This is very similar to
ValueProcessor.getValueFromContainer(ValueContainer)
except that instead of an
actual value, a Value
or extension there of is returned.getApiValueFromContainer
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
container
- The container to get the API value fromValue
typed valuepublic org.spongepowered.api.data.DataTransactionResult offerToStore(org.spongepowered.api.data.value.ValueContainer<?> container, E value)
ValueProcessor
BaseValue
containing a value of the
appropriate value type of this ValueProcessor
to offer
back to the ValueContainer
.offerToStore
in interface ValueProcessor<E,V extends org.spongepowered.api.data.value.BaseValue<E>>
container
- The value containervalue
- The value