Skip to content

Comments

API 8: Data#981

Merged
mosemister merged 4 commits intoSpongePowered:stablefrom
mosemister:api8/data
Mar 29, 2024
Merged

API 8: Data#981
mosemister merged 4 commits intoSpongePowered:stablefrom
mosemister:api8/data

Conversation

@mosemister
Copy link
Member

When it comes to user facing stuff on data, a lot of it is the same as API 7, therefore only imports and method names have changed.

However vanilla DataManipulators have moved to Sponge (common) instead of being expose to the API and the ranged Value has also been removed. This has caused some major deletions and some examples to change.

The largest change comes in custom data, whereby the custom DataHolder has been removed (as it wasnt even written in API 7) and Serialization as well as DataManipulators have been combined into a single page (as they have in the Sponge API). This has resulted in the Custom drop down menu to only hold a single page, so I would be more then happy to bring the DataManipulator page up a parent and rename to Custom DataManipulator

@mosemister mosemister added this to the v8.0.0 milestone Aug 14, 2023
@mosemister mosemister added needs review The submission is ready and needs to be reviewed outdated docs The API has changed and the docs are outdated labels Aug 14, 2023
Copy link
Member

@Inscrutable Inscrutable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor quibbles alone, great work again. And I concur we should bump it up an index level in the docs if you don't foresee the need to have any further pages in the section.


Simple Custom Data
==================

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention this earlier? No need to read how to create more complex custom data if you just want a string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts was to learn how it works and then learn how to shortcut the process. But ill make it earlier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

@mosemister mosemister closed this Sep 4, 2023
@mosemister mosemister deleted the api8/data branch September 4, 2023 09:36
@mosemister mosemister restored the api8/data branch September 4, 2023 09:36
@mosemister
Copy link
Member Author

Not sure how this one got closed. Must be by accident

@mosemister mosemister reopened this Dec 31, 2023
Comment on lines +102 to +107
Registering your ``DataSerializable`` allows it to be accessible by Sponge and by other plugins in a generic way. The
game/plugin can create copies of your data and serialize/deserialize your data without referencing any of your classes
directly.

To register a ``DataSerializable`` Sponge has the :javadoc:`RegisterDataEvent` event. This will allow you to register
your data with the appropriate ``DataHolder``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd almost reword this that the DataSerializable isn't the core intent of it being accessible, moreso that it's persisted to Minecraft's traditional data objects that can support custom data (Items, Entities, BlockEntities), accessible via the author's registered Key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically mentioning that custom data is most easily accessible via Keys, DataSerializable is only one of two options to making data persisted.

import org.spongepowered.api.data.Key;
import org.spongepowered.api.data.value.Value;

ResourceKey resourceKey = ResourceKey(pluginContainer, "last_attacker_manipulator");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove manipulator and use something more like last_attacker_data


.. warning::

Be sure to store your ``Key`` somewhere global so you can access it later.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Be sure to store your ``Key`` somewhere global so you can access it later.
Retain your ``Key`` reference readily available for later access, otherwise you incur additional processing expense recreating a new `Key` each time.

Although, I'm unsure whether we use equality or ResourceKey equality for comparison.


.. tip::

You can register a key for a specific element within a DataSerializable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Can you clarify what element means? Are we talking about a field of an Object implementing DataSerializable?

Comment on lines +152 to +154
The :javadoc:`DataStore` is used to register your ``Key`` with the appropriate ``DataHolder`` and also register
any other keys you may have accessing your ``DataSerializable``. In the example below, it creates a ``DataStore``
and makes it appliciable to only the :javadoc:`Entity` ``DataHolder``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention how this is to enable the DataHolder's mode of persistence to know where/how to store the data backed by the Key in that automatic serialization and deserialization (based on whether it's simple or a DataSerializable kind).

Comment on lines +199 to +203
a ``DataProvider``. With a ``dataProvider`` a plugin is able to manipulate how its data should be received, set, and
deleted automatically.

In the following example, we will be getting the UUID from the last attacker but if there is no last attacker, then
return the player's UUID instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also equally to enable external persistence of the Keyed data for a plugin to be able to consume/provide said data, such as a database.

Comment on lines +231 to +244
The final object you will need to register your data is the :javadoc:`DataRegistration` which combines
your ``Key``, ``DataStore`` and ``DataProvider`` together into a single package that you can register.

.. code-block:: java

import org.spongepowered.api.data.DataRegistration;

DataRegistration myData = DataRegistration.builder()
.key(key)
.store(datastore)
.provider(provider)
.build();

event.register(myData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that not including a store or provider means the data will simply be ephemeral and has no guarantees to the persistence of said data. This means if an Entity has some custom data offered, it will accept it, but not persist it.

Copy link
Member

@gabizou gabizou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good enough to merge

@mosemister
Copy link
Member Author

Ill merge, but have a follow up pr soon addressing the comments

@mosemister mosemister merged commit 75bd738 into SpongePowered:stable Mar 29, 2024
@mosemister mosemister deleted the api8/data branch August 19, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review The submission is ready and needs to be reviewed outdated docs The API has changed and the docs are outdated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants