Package org.spongepowered.api.data
Interface DataManager
-
public interface DataManagerA manager of the overall Data API. This handles the registration ofDataSerializables and theirDataBuilders,DataRegistrations, 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 theDataBuilderfor the desiredDataSerializableclass.DataContainercreateContainer()Creates a newDataContainerwith a defaultDataView.SafetyModeofDataView.SafetyMode.ALL_DATA_CLONED.DataContainercreateContainer(DataView.SafetyMode safety)Creates a newDataContainerwith the providedDataView.SafetyMode.<T extends DataSerializable>
Optional<T>deserialize(Class<T> clazz, DataView dataView)Attempts to translate an instance of theDataSerializablefrom 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.Immutableclass with it's associatedDataHolderBuilder.Immutable.<T extends DataSerializable>
voidregisterBuilder(Class<T> clazz, DataBuilder<T> builder)Registers aDataBuilderthat will dynamically build the givenDataSerializablefrom aDataContainer.<T extends DataSerializable>
voidregisterContentUpdater(Class<T> clazz, DataContentUpdater updater)Registers aDataContentUpdaterfor the desiredDataSerializablesuch that any versioned data may be updated to newer versions for the most up to dateDataBuilder.voidregisterLegacyManipulatorIds(String legacyId, ResourceKey dataStoreKey)Registers a legacyidthat is used by a previous version ofDataRegistrationfrom 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 desiredDataTranslatorfor the provided class.<T extends DataSerializable>
Optional<DataContentUpdater>wrappedContentUpdater(Class<T> clazz, int fromVersion, int toVersion)Gets a wrapped fakeDataContentUpdaterthat may wrap severalDataContentUpdaters to translate versioned data from the desiredfromVersionto thetoVersion.
-
-
-
Method Detail
-
registerBuilder
<T extends DataSerializable> void registerBuilder(Class<T> clazz, DataBuilder<T> builder)
Registers aDataBuilderthat will dynamically build the givenDataSerializablefrom aDataContainer.Builders may not always exist for a given
DataSerializable, nor is it guaranteed that a provided builder will function with allDataContainers.- Type Parameters:
T- The type of data serializable- Parameters:
clazz- The class of theDataSerializablebuilder- The builder that can build the data serializable
-
registerContentUpdater
<T extends DataSerializable> void registerContentUpdater(Class<T> clazz, DataContentUpdater updater)
Registers aDataContentUpdaterfor the desiredDataSerializablesuch 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 fakeDataContentUpdaterthat may wrap severalDataContentUpdaters to translate versioned data from the desiredfromVersionto thetoVersion. If the version jump is too great or aDataContentUpdaterhas 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 theDataBuilderfor the desiredDataSerializableclass.Builders may not always exist for a given
DataSerializable, nor is it guaranteed that a provided builder will function with allDataContainers.- 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 theDataSerializablefrom the providedDataView. If there is noDataBuilderregistered 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.Immutableclass with it's associatedDataHolderBuilder.Immutable. The builder can be used to create new instances of the givenDataHolder.Immutablefor 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 legacyidthat is used by a previous version ofDataRegistrationfrom 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.Immutablewas 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 desiredDataTranslatorfor 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 newDataContainerwith a defaultDataView.SafetyModeofDataView.SafetyMode.ALL_DATA_CLONED.- Returns:
- A new data container
-
createContainer
DataContainer createContainer(DataView.SafetyMode safety)
Creates a newDataContainerwith the providedDataView.SafetyMode.- Parameters:
safety- The safety mode to use- Returns:
- A new data container with the provided safety mode
- See Also:
DataView.SafetyMode
-
-