public interface DataManager
DataSerializable
s and their DataBuilder
s,
DataManipulator
s and their respective DataManipulatorBuilder
s,
ImmutableDataManipulator
s and their respective
ImmutableDataManipulatorBuilder
s, etc.
Note that this manager powers not just serialization and deserialization, but also powers a majority of the Data API.
Modifier and Type | Method and Description |
---|---|
DataContainer |
createContainer()
Creates a new
DataContainer with a default
DataView.SafetyMode of
DataView.SafetyMode.ALL_DATA_CLONED . |
DataContainer |
createContainer(DataView.SafetyMode safety)
Creates a new
DataContainer with the provided
DataView.SafetyMode . |
<T extends DataSerializable> |
deserialize(Class<T> clazz,
DataView dataView)
Attempts to translate an instance of the
DataSerializable from
the provided DataView . |
Collection<Class<? extends DataManipulator<?,?>>> |
getAllRegistrationsFor(PluginContainer container)
|
<T extends DataSerializable> |
getBuilder(Class<T> clazz)
Attempts to retrieve the
DataBuilder for the desired
DataSerializable class. |
<T extends ImmutableDataHolder<T>,B extends ImmutableDataBuilder<T,B>> |
getImmutableBuilder(Class<T> holderClass)
Attempts to retrieve the builder for the given
ImmutableDataHolder . |
<T extends DataManipulator<T,I>,I extends ImmutableDataManipulator<I,T>> |
getImmutableManipulatorBuilder(Class<I> immutableManipulatorClass)
Attempts to retrieve the builder for the given
ImmutableDataManipulator . |
<T extends DataManipulator<T,I>,I extends ImmutableDataManipulator<I,T>> |
getManipulatorBuilder(Class<T> manipulatorClass)
Attempts to retrieve the builder for the given
DataManipulator . |
<T> Optional<DataTranslator<T>> |
getTranslator(Class<T> objectClass)
Gets the desired
DataTranslator for the provided class. |
<T extends DataSerializable> |
getWrappedContentUpdater(Class<T> clazz,
int fromVersion,
int toVersion)
Gets a wrapped fake
DataContentUpdater that may wrap several
DataContentUpdater s to translate versioned data from the desired
fromVersion to the toVersion . |
<T extends ImmutableDataHolder<T>,B extends ImmutableDataBuilder<T,B>> |
register(Class<T> holderClass,
B builder)
Registers the given
ImmutableDataHolder class with it's
associated ImmutableDataBuilder . |
<T extends DataSerializable> |
registerBuilder(Class<T> clazz,
DataBuilder<T> builder)
Registers a
DataBuilder that will dynamically build
the given DataSerializable from a DataContainer . |
<T extends DataSerializable> |
registerContentUpdater(Class<T> clazz,
DataContentUpdater updater)
Registers a
DataContentUpdater for the desired
DataSerializable such that any versioned data may be updated to
newer versions for the most up to date DataBuilder . |
void |
registerLegacyManipulatorIds(String legacyId,
DataRegistration<?,?> registration)
Registers a legacy
id that is used by a previous version of
DataRegistration from a plugin such that the custom data can
be retained, while not being lost. |
<T> void |
registerTranslator(Class<T> objectClass,
DataTranslator<T> translator)
Deprecated.
Use the event
org.spongepowered.api.event.game.GameRegistryEvent.Register<DataTranslator<?>> instead |
<T extends DataSerializable> void registerBuilder(Class<T> clazz, DataBuilder<T> builder)
DataBuilder
that will dynamically build
the given DataSerializable
from a DataContainer
.
Builders may not always exist for a given DataSerializable
,
nor is it guaranteed that a provided builder will function with all
DataContainer
s.
T
- The type of data serializableclazz
- The class of the DataSerializable
builder
- The builder that can build the data serializable<T extends DataSerializable> void registerContentUpdater(Class<T> clazz, DataContentUpdater updater)
DataContentUpdater
for the desired
DataSerializable
such that any versioned data may be updated to
newer versions for the most up to date DataBuilder
.T
- The type of DataSerializableclazz
- The data serializable classupdater
- The updater<T extends DataSerializable> Optional<DataContentUpdater> getWrappedContentUpdater(Class<T> clazz, int fromVersion, int toVersion)
DataContentUpdater
that may wrap several
DataContentUpdater
s to translate versioned data from the desired
fromVersion
to the toVersion
. If the version jump is too
great or a DataContentUpdater
has not been registered to cover
the complete jump, Optional.empty()
may be returned.T
- The type of data serializableclazz
- The data serializable classfromVersion
- The version converting fromtoVersion
- The version converting to<T extends DataSerializable> Optional<DataBuilder<T>> getBuilder(Class<T> clazz)
DataBuilder
for the desired
DataSerializable
class.
Builders may not always exist for a given DataSerializable
,
nor is it guaranteed that a provided builder will function with all
DataContainer
s.
T
- The type of data serializableclazz
- The class of the data serializable<T extends DataSerializable> Optional<T> deserialize(Class<T> clazz, DataView dataView)
DataSerializable
from
the provided DataView
. If there is no DataBuilder
registered for the provided DataSerializable
, then
Optional.empty()
may be returned.T
- The type of data serializableclazz
- The class of the data serializabledataView
- The data view containing raw data<T extends ImmutableDataHolder<T>,B extends ImmutableDataBuilder<T,B>> void register(Class<T> holderClass, B builder)
ImmutableDataHolder
class with it's
associated ImmutableDataBuilder
. The builder can be used to
create new instances of the given ImmutableDataHolder
for data
retrieval, data representation, etc.T
- The type of immutable data holderB
- The type of immutable data builderholderClass
- The class of the immutable data holderbuilder
- The builder instance of the immutable data holdervoid registerLegacyManipulatorIds(String legacyId, DataRegistration<?,?> registration)
id
that is used by a previous version of
DataRegistration
from a plugin such that the custom data can
be retained, while not being lost.legacyId
- The legacy idregistration
- The registration object successfully created<T extends ImmutableDataHolder<T>,B extends ImmutableDataBuilder<T,B>> Optional<B> getImmutableBuilder(Class<T> holderClass)
ImmutableDataHolder
.
If the ImmutableDataHolder
was not registered, multiple
systems could fail to retrieve specific data.
T
- The type of immutable data holderB
- The type of immutable data builderholderClass
- The immutable data holder class<T extends DataManipulator<T,I>,I extends ImmutableDataManipulator<I,T>> Optional<DataManipulatorBuilder<T,I>> getManipulatorBuilder(Class<T> manipulatorClass)
DataManipulator
.
If the DataManipulator
was not registered, multiple systems
could fail to retrieve specific data.
T
- The type of manipulatorI
- The type of immutable manipulatormanipulatorClass
- The manipulator class<T extends DataManipulator<T,I>,I extends ImmutableDataManipulator<I,T>> Optional<DataManipulatorBuilder<T,I>> getImmutableManipulatorBuilder(Class<I> immutableManipulatorClass)
ImmutableDataManipulator
.
If the ImmutableDataManipulator
was not registered, multiple
systems could fail to retrieve specific data.
T
- The type of DataManipulatorI
- The type of ImmutableDataManipulatorimmutableManipulatorClass
- The immutable manipulator class@Deprecated <T> void registerTranslator(Class<T> objectClass, DataTranslator<T> translator)
org.spongepowered.api.event.game.GameRegistryEvent.Register<DataTranslator<?>>
insteadDataTranslator
for the desired class.T
- The type of objectobjectClass
- The class of the object type being managedtranslator
- The translator for the desired class object<T> Optional<DataTranslator<T>> getTranslator(Class<T> objectClass)
DataTranslator
for the provided class.T
- The type of objectobjectClass
- The class of the objectCollection<Class<? extends DataManipulator<?,?>>> getAllRegistrationsFor(PluginContainer container)
Class
es of all DataManipulator
s registered for
the provided PluginContainer
. The provided Collection
is
considered immutable and can not be modified.container
- The plugin container for registered classesDataContainer createContainer()
DataContainer
with a default
DataView.SafetyMode
of
DataView.SafetyMode.ALL_DATA_CLONED
.DataContainer createContainer(DataView.SafetyMode safety)
DataContainer
with the provided
DataView.SafetyMode
.safety
- The safety mode to useDataView.SafetyMode