Package org.spongepowered.api.data
Interface DataManager
-
public interface DataManager
A manager of the overall Data API. This handles the registration ofDataSerializable
s and theirDataBuilder
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends DataSerializable>
Optional<DataBuilder<T>>builder(Class<T> clazz)
Attempts to retrieve theDataBuilder
for the desiredDataSerializable
class.DataContainer
createContainer()
Creates a newDataContainer
with a defaultDataView.SafetyMode
ofDataView.SafetyMode.ALL_DATA_CLONED
.DataContainer
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>>
voidregister(Class<T> holderClass, B builder)
Registers 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> 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 Detail
-
registerBuilder
<T extends DataSerializable> void registerBuilder(Class<T> clazz, DataBuilder<T> builder)
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
<T extends DataSerializable> Optional<DataBuilder<T>> builder(Class<T> clazz)
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
<T extends DataSerializable> Optional<T> deserialize(Class<T> clazz, DataView dataView)
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,B>> void register(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
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.- Parameters:
legacyId
- The legacy iddataStoreKey
- The dataStore key set inDataStore.Builder.pluginData(ResourceKey)
-
immutableBuilder
<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
.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
<T> Optional<DataTranslator<T>> translator(Class<T> objectClass)
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
-
createContainer
DataContainer createContainer()
Creates a newDataContainer
with a defaultDataView.SafetyMode
ofDataView.SafetyMode.ALL_DATA_CLONED
.- Returns:
- A new data container
-
createContainer
DataContainer createContainer(DataView.SafetyMode safety)
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:
DataView.SafetyMode
-
-