Interface DataManager


  • public interface DataManager
    A manager of the overall Data API. This handles the registration of DataSerializables and their DataBuilders, DataRegistrations, etc.

    Note that this manager powers not just serialization and deserialization, but also powers a majority of the Data API.

    • Method Detail

      • registerContentUpdater

        <T extends DataSerializable> void registerContentUpdater​(java.lang.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.
        Type Parameters:
        T - The type of DataSerializable
        Parameters:
        clazz - The data serializable class
        updater - The updater
      • wrappedContentUpdater

        <T extends DataSerializable> java.util.Optional<DataContentUpdater> wrappedContentUpdater​(java.lang.Class<T> clazz,
                                                                                                  int fromVersion,
                                                                                                  int toVersion)
        Gets a wrapped fake DataContentUpdater that may wrap several DataContentUpdaters 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.
        Type Parameters:
        T - The type of data serializable
        Parameters:
        clazz - The data serializable class
        fromVersion - The version converting from
        toVersion - 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 the 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 DataContainers.

        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 the DataSerializable from the provided DataView. If there is no DataBuilder registered for the provided DataSerializable, then Optional.empty() may be returned.
        Type Parameters:
        T - The type of data serializable
        Parameters:
        clazz - The class of the data serializable
        dataView - 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 given DataHolder.Immutable class with it's associated DataHolderBuilder.Immutable. The builder can be used to create new instances of the given DataHolder.Immutable for data retrieval, data representation, etc.
        Type Parameters:
        T - The type of immutable data holder
        B - The type of immutable data builder
        Parameters:
        holderClass - The class of the immutable data holder
        builder - The builder instance of the immutable data holder
      • registerLegacyManipulatorIds

        void registerLegacyManipulatorIds​(java.lang.String legacyId,
                                          ResourceKey dataStoreKey)
        Registers a legacy id that is used by a previous version of DataRegistration from a plugin such that the custom data can be read by a plugin-data datastore.
        Parameters:
        legacyId - The legacy id
        dataStoreKey - The dataStore key set in DataStore.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 given DataHolder.Immutable.

        If the DataHolder.Immutable was not registered, multiple systems could fail to retrieve specific data.

        Type Parameters:
        T - The type of immutable data holder
        B - 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 desired DataTranslator 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 a DataTranslator for the desired class.
        Type Parameters:
        T - The type of object
        Parameters:
        objectClass - The class of the object type being managed
        translator - The translator for the desired class object