Package org.spongepowered.api.data
Interface DataManager
public interface DataManager
A manager of the overall Data API. This handles the registration of
DataSerializable
s and their DataBuilder
s,
DataRegistration
s, etc.
Note that this manager powers not just serialization and deserialization, but also powers a majority of the Data API.
-
Method Summary
Modifier and TypeMethodDescription<T extends DataSerializable>
Optional<DataBuilder<T>>Attempts to retrieve theDataBuilder
for the desiredDataSerializable
class.Creates a newDataContainer
with a defaultDataView.SafetyMode
ofDataView.SafetyMode.ALL_DATA_CLONED
.createContainer
(DataView.SafetyMode safety) Creates a newDataContainer
with the providedDataView.SafetyMode
.<T extends DataSerializable>
Optional<T>deserialize
(Class<T> clazz, DataView dataView) Attempts to translate an instance of theDataSerializable
from the providedDataView
.<T extends DataHolder.Immutable<T>,
B extends DataHolderBuilder.Immutable<T, B>>
Optional<B>immutableBuilder
(Class<T> holderClass) Attempts to retrieve the builder for the givenDataHolder.Immutable
.<T extends DataHolder.Immutable<T>,
B extends DataHolderBuilder.Immutable<T, B>>
voidRegisters the givenDataHolder.Immutable
class with it's associatedDataHolderBuilder.Immutable
.<T extends DataSerializable>
voidregisterBuilder
(Class<T> clazz, DataBuilder<T> builder) Registers aDataBuilder
that will dynamically build the givenDataSerializable
from aDataContainer
.<T extends DataSerializable>
voidregisterContentUpdater
(Class<T> clazz, DataContentUpdater updater) Registers aDataContentUpdater
for the desiredDataSerializable
such that any versioned data may be updated to newer versions for the most up to dateDataBuilder
.void
registerLegacyManipulatorIds
(String legacyId, ResourceKey dataStoreKey) Registers a legacyid
that is used by a previous version ofDataRegistration
from a plugin such that the custom data can be read by a plugin-data datastore.<T> void
registerTranslator
(Class<T> objectClass, DataTranslator<T> translator) Registers aDataTranslator
for the desired class.<T> Optional<DataTranslator<T>>
translator
(Class<T> objectClass) Gets the desiredDataTranslator
for the provided class.<T extends DataSerializable>
Optional<DataContentUpdater>wrappedContentUpdater
(Class<T> clazz, int fromVersion, int toVersion) Gets a wrapped fakeDataContentUpdater
that may wrap severalDataContentUpdater
s to translate versioned data from the desiredfromVersion
to thetoVersion
.
-
Method Details
-
registerBuilder
Registers aDataBuilder
that will dynamically build the givenDataSerializable
from aDataContainer
.Builders may not always exist for a given
DataSerializable
, nor is it guaranteed that a provided builder will function with allDataContainer
s.- Type Parameters:
T
- The type of data serializable- Parameters:
clazz
- The class of theDataSerializable
builder
- The builder that can build the data serializable
-
registerContentUpdater
<T extends DataSerializable> void registerContentUpdater(Class<T> clazz, DataContentUpdater updater) Registers aDataContentUpdater
for the desiredDataSerializable
such that any versioned data may be updated to newer versions for the most up to dateDataBuilder
.- Type Parameters:
T
- The type of DataSerializable- Parameters:
clazz
- The data serializable classupdater
- The updater
-
wrappedContentUpdater
<T extends DataSerializable> Optional<DataContentUpdater> wrappedContentUpdater(Class<T> clazz, int fromVersion, int toVersion) Gets a wrapped fakeDataContentUpdater
that may wrap severalDataContentUpdater
s to translate versioned data from the desiredfromVersion
to thetoVersion
. If the version jump is too great or aDataContentUpdater
has not been registered to cover the complete jump,Optional.empty()
may be returned.- Type Parameters:
T
- The type of data serializable- Parameters:
clazz
- The data serializable classfromVersion
- The version converting fromtoVersion
- The version converting to- Returns:
- The content updater, if available
-
builder
Attempts to retrieve theDataBuilder
for the desiredDataSerializable
class.Builders may not always exist for a given
DataSerializable
, nor is it guaranteed that a provided builder will function with allDataContainer
s.- Type Parameters:
T
- The type of data serializable- Parameters:
clazz
- The class of the data serializable- Returns:
- The builder, if available
-
deserialize
Attempts to translate an instance of theDataSerializable
from the providedDataView
. If there is noDataBuilder
registered for the providedDataSerializable
, thenOptional.empty()
may be returned.- Type Parameters:
T
- The type of data serializable- Parameters:
clazz
- The class of the data serializabledataView
- The data view containing raw data- Returns:
- The data serializable, if available
-
register
<T extends DataHolder.Immutable<T>,B extends DataHolderBuilder.Immutable<T, void registerB>> (Class<T> holderClass, B builder) Registers the givenDataHolder.Immutable
class with it's associatedDataHolderBuilder.Immutable
. The builder can be used to create new instances of the givenDataHolder.Immutable
for data retrieval, data representation, etc.- Type Parameters:
T
- The type of immutable data holderB
- The type of immutable data builder- Parameters:
holderClass
- The class of the immutable data holderbuilder
- The builder instance of the immutable data holder
-
registerLegacyManipulatorIds
Registers a legacyid
that is used by a previous version ofDataRegistration
from a plugin such that the custom data can be read by a plugin-data datastore.- Parameters:
legacyId
- The legacy iddataStoreKey
- The dataStore key set inDataStore.Builder.pluginData(ResourceKey)
-
immutableBuilder
<T extends DataHolder.Immutable<T>,B extends DataHolderBuilder.Immutable<T, Optional<B> immutableBuilderB>> (Class<T> holderClass) Attempts to retrieve the builder for the givenDataHolder.Immutable
.If the
DataHolder.Immutable
was not registered, multiple systems could fail to retrieve specific data.- Type Parameters:
T
- The type of immutable data holderB
- The type of immutable data builder- Parameters:
holderClass
- The immutable data holder class- Returns:
- The builder, if available
-
translator
Gets the desiredDataTranslator
for the provided class.- Type Parameters:
T
- The type of object- Parameters:
objectClass
- The class of the object- Returns:
- The data translator, if available
-
registerTranslator
Registers aDataTranslator
for the desired class.- Type Parameters:
T
- The type of object- Parameters:
objectClass
- The class of the object type being managedtranslator
- The translator for the desired class object
-
createContainer
DataContainer createContainer()Creates a newDataContainer
with a defaultDataView.SafetyMode
ofDataView.SafetyMode.ALL_DATA_CLONED
.- Returns:
- A new data container
-
createContainer
Creates a newDataContainer
with the providedDataView.SafetyMode
.- Parameters:
safety
- The safety mode to use- Returns:
- A new data container with the provided safety mode
- See Also:
-