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>
java.util.Optional<DataBuilder<T>>builder(java.lang.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>
java.util.Optional<T>deserialize(java.lang.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>>
java.util.Optional<B>immutableBuilder(java.lang.Class<T> holderClass)
Attempts to retrieve the builder for the givenDataHolder.Immutable
.<T extends DataHolder.Immutable<T>,B extends DataHolderBuilder.Immutable<T,B>>
voidregister(java.lang.Class<T> holderClass, B builder)
Registers the givenDataHolder.Immutable
class with it's associatedDataHolderBuilder.Immutable
.<T extends DataSerializable>
voidregisterBuilder(java.lang.Class<T> clazz, DataBuilder<T> builder)
Registers aDataBuilder
that will dynamically build the givenDataSerializable
from aDataContainer
.<T extends DataSerializable>
voidregisterContentUpdater(java.lang.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(java.lang.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(java.lang.Class<T> objectClass, DataTranslator<T> translator)
Registers aDataTranslator
for the desired class.<T> java.util.Optional<DataTranslator<T>>
translator(java.lang.Class<T> objectClass)
Gets the desiredDataTranslator
for the provided class.<T extends DataSerializable>
java.util.Optional<DataContentUpdater>wrappedContentUpdater(java.lang.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(java.lang.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(java.lang.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> java.util.Optional<DataContentUpdater> wrappedContentUpdater(java.lang.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> java.util.Optional<DataBuilder<T>> builder(java.lang.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> java.util.Optional<T> deserialize(java.lang.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(java.lang.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(java.lang.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>> java.util.Optional<B> immutableBuilder(java.lang.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> java.util.Optional<DataTranslator<T>> translator(java.lang.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
-
registerTranslator
<T> void registerTranslator(java.lang.Class<T> objectClass, DataTranslator<T> translator)
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
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
-
-