Help migrating custom-data to API 7 registration - PR notes not accurate

I’ve seen this article: Refactor Data Registration by gabizou · Pull Request #1531 · SpongePowered/SpongeAPI · GitHub that talks about the changes to the custom-data system, and registration…

However, the changes are presented as “It is going to be like…” but the actual stuff is different.

It shows to replace
Sponge.getDataManager().register(MyCustomData.class, ImmutableCustomData.class, new CustomDataBuilder());

as like

DataRegistration.<MyCustomData, ImmutableCustomData>builder()
      .setDataClass(MyCustomData.class)
      .setImmutableDataClass(ImmutableCustomData.class)
      .setBuilder(new CustomDataBuilder())
      .setManipulatorId("my_custom")
      .buildAndRegister(this);

There are no setX methods - there are similar without the set part, but this then results in builder() being both the datareg builder command, and the builder-specifier… ? ?

It also specifies that we NEED to provide the data-typing in the dataregistration line, but whenever I try to produce a similar opening construction in Eclipse to what is listed above, I get a much bigger pile of spaghetti.

For me trying to migrate
Sponge.getDataManager().register(FrameLockData.class, new FrameLockDataManipulatorBuilder());

I can get something like below by forcibly overwriting what eclipse auto-fills for me:

DataRegistration.<FrameLockData, ImmutableFrameLockData> builder()
        .dataClass(FrameLockData.class)
        .immutableClass(ImmutableFrameLockData.class)
        .builder(new FrameLockDataManipulatorBuilder())
        .manipulatorId("booFLD")
        .buildAndRegister(this.container);

But then Eclipse is tossing warnings at me “Unused type arguments for the non generic method builder() of type DataRegistration; it should not be parameterized with arguments <FrameLockData, ImmutableFrameLockData>” because if I go ahead and just type DataRegistration as soon as I press the period and left brace, it auto-fills in as

DataRegistration.Builder<DataManipulator<T,I>, ImmutableDataManipulator<I,T>>

Which to my small brain says that it wants to go inception-like and simply replacing with the mut and immutable data class names isn’t enough, it wants something more from each still… plus, I can’t seem to then manipulate that form into one into a working builder-construct.

Its possible my eclipse settings are such as to over-warn something, or to auto-do something that shouldn’t be done, and I need to disable something, but what should the REAL CORRECT END-PRODUCT LOOK LIKE now for the sample code, since the “will look like” is not accurate and there may be other issues at stake now.

DataRegistration.builder()
gives no warnings, and compiles, but goes against the exposition in the PR about how the generics need to be specified because thats how Java is in this case… and it also ends up resulting in a NPE: Data name is null! error when compiled.

Please help me produce the correct migratory code form, and if my eclipse settings will not permit it without a warning or restructuring it, indicate what setting i should toggle if that is known.

Thanks

If your generics compile, then your generics are good. Type erasure means that your generics do not actually appear in the compiled code, so whatever compiles, will work. Unsure why the PR says to put the type parameters in, the method doesn’t even have type parameters (which is what Eclipse is telling you - that you don’t need them), and it works just fine without them. And an easy way to fix a null data name would be to add a dataName call.

Because I edited it with the commit afterwards.

You also have to provide a name, It helps to actually look at the builder class in question and see what methods are available.

1 Like

Okay, so then what role does the dataName play in the grand scheme of things, if we are already providing a unique manipulatorId string?

Do these two strings need to be identical, or do they absolutely need to be different from each other. Do they need to be linked to the classnames in someway?

Can someone please provide an exact sample copy of the code so that everyone can reference an example of the migratory code that works, instead of everyone having to dive into the depths and reverse engineer what is necessary and what is not and what types of strings work and what will blow up?

1 Like

Guys, please…

If you guys thought I was being aggressive or jerkish in the response above, I assure you that was not the intention.

The intention was to try to get information to help myself and other people here to document a system that has a partial blob of documentation, but not exactly, to bridge a point between “Hey, you need to make a change to the way something is done here, in the style of this planned change…” and the actual endpoint.

I don’t have the skills to be able to chase through all the systems to find out what the upstream /downstream issues are – yes, “you can check the builder for what is available…” but available does not mean manditory, when translating the “use this structure to make your data” planned example. Sure, okay, i could have figured out ‘dataname’ from the error and builder.

But here’s the thing.

The dataname string comes flying out of thin air, with no explanation of its meaning and context.
Supply two strings strings to the builder - one that was described somewhat , but the other comes from what/means what/implies what/is used how downstream. Is it something to be just internally handled, or something to be externally used later in data-manipulating things?

What is the difference between the two strings, in the sense that should one have a particular nomenclature style, and the other can be anything. Do they have to be unique between plugins entirely, can different plugins have one string called “blah” yet sponge will automatically unique-ify these to different things?

When I say “downstream/upstream” implications, this is what I mean. How unique do the strings need to be? Can they have the same value - is there benefit to making them different strings? Are there nomenclature suggestions and usage requirements? Will using a period within a string cause the system to explode when reloading map files after a reboot? Are the characters in the string restricted , or rather, should they be to avoid potential issues?

If two strings are required for the data system, how are they used differently such that internally, sponge hasn’t automatically reused the one string for the other purpose? If its a matter of like, requiring the sponge server to make an official registration of “Robert_Eugene_Smith” in a system somewhere to associate with the datastructures and classes, but then also being able to provide “Bobby” with it, which part impacts the NBT data files? Where does calling the dataname “Bobby” give benefit by this additional name?

My concern is primarily with that of wanting to know what restrictions are on these strings, so as to avoid error explosions and file corruption issues at some point after a server reboot encounters the files, for example, or weeks later. And to identify what recommendations are in place for the strings, so as to avoid explosions with different plugins having similar strings, or if that is even an issue.

Please.

Thank you.

I had a look through Sponge’s data registration code, the data “name” and “ID” are needed because DataRegistration extends CatalogType, so the meaning of both name and ID are that of a catalog. i.e. the name is human readable, and ID is unique (unique to the plugin since it’s prefixed as plugin_id:data_Id)

Thank you simon816…

So two or more plugins could register the id of “mydata” for a single data unit , but that wont matter because internally those are concatenated with the plugin id itself to create the unique ID…

But what if two plugins use “MyData” as the name, will that end up causing some collision? And how does setting the name mean anything to my plugin or folks using my plugin later - I know the id is for determining the class to work with the object data, but what if I name my custom data NAMEs as “HorseyMcHorseface” and “Robert” ? I’m pretty sure in my plugin, I’ll only be working with “FrameLockData” objects and Keys for those, so registering the name “Robert” doesn’t look like it would have an impact on my plugin anywhere – but where would this come back to bite me in the arse later naming it Robert instead of “BoosFrameLock” , wrt other plugins perhaps?

Not that I would use a name like “mydata” or “Robert” but the concern is for things like various plugins that may use “warpdata” or “lockdata” etc type generic, meaningful names to end up possibly conflicting for the names, and where those come into the big picture…

Names have no guarantee of being unique, they are primarily for human readability and can even just be the ID.
I don’t think sponge uses the name anywhere. I can imagine it being used for printing data about a particular object
e.g." An item has MyData", or, “MyData is missing on this entity” or whatever.
All other plugins, and sponge, will be referencing the data’s ID so names are not important for identification.