Skip to content

[Feature] Add API to query type of PersistentDataContainer value - #14143

Open
Keksnet wants to merge 6 commits into
PaperMC:mainfrom
Keksnet:feature/get-type-of-pdc-element
Open

[Feature] Add API to query type of PersistentDataContainer value#14143
Keksnet wants to merge 6 commits into
PaperMC:mainfrom
Keksnet:feature/get-type-of-pdc-element

Conversation

@Keksnet

@Keksnet Keksnet commented Aug 5, 2026

Copy link
Copy Markdown

Hi,
this PR adds a method that makes it possible to query the data type of a specific value inside a persistent data container.
With this method it will be possible to read a value without knowing the exact type of the value you are trying to read.
This is useful for migrating the data type of a value to another one or for a library that sits on top of Paper and does not know the type by design.
It enables further tools like editors for the persistent data container to be developed without the need to check every available data type or using a nbt API.

I have tested the method using the test-plugin and can provide my testing code if necessary.

This API in its current form is not able to correctly determine the data type of nested lists but I'm already trying to fix this issue. Already fixed.

Any question or feedback is welcome. 🙂

Keksnet added 2 commits August 4, 2026 17:17
This is the initial implementation of PersistentDataContainerView.getType.
The method makes it possible for callees to retrieve the data type of a specific persistent data container key.
@Keksnet
Keksnet requested a review from a team as a code owner August 5, 2026 12:46
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Aug 5, 2026
@Keksnet

Keksnet commented Aug 5, 2026

Copy link
Copy Markdown
Author

Detection of nested lists is now fixed.

@lynxplay

lynxplay commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I am not much of a fan of such an method, definitely not under the proposed method name at least.

Type information is not encoded. A plugin inserting a value using PersistentDataType A is not guaranteed to receive said data type when querying the PDC#getType().
This is already true for every plugin maintained type but even spreads to API exposed types like BOOLEAN.

Maybe PDCV#estimatePrimitiveDataType(Key) could work? With a large amount of notice in the javadocs.

@Keksnet

Keksnet commented Aug 5, 2026

Copy link
Copy Markdown
Author

@lynxplay I totally missed the possibility of plugin-specific data types. I renamed the method and edited the javadocs. This should hopefully reflect that this method is essentially only estimating the data type based on the underlying nbt tag.
I also changed the type of the key argument from NamespacedKey to Key (from adventure). This should make it easier to integrate with existing adventure code and no require a remapping from Key -> NamespacedKey.
This is not a problem for any code, as NamespacedKey implements Key.

@Leguan16

Leguan16 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I personally don't really like the name estimatePrimitiveDataType. What do you all think about getStorageType, as in "the type the PDC is stored in"?

@Keksnet

Keksnet commented Aug 5, 2026

Copy link
Copy Markdown
Author

@Leguan16 I personally think the storage type thing is too abstract. I would maybe suggest getNbtTagType. I'm worried that this name would be inaccurate as there is nothing that says, that pdc data will always be stored inside nbt tags.

@Leguan16

Leguan16 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I would maybe suggest getNbtTagType

The issue with this name is that there is no concept of NBT in the API I think. So it could be a confusing name.

@Keksnet

Keksnet commented Aug 5, 2026

Copy link
Copy Markdown
Author

getStorageType would be fine if I add an explanation to the javadocs to explain what the storage type is. I think it would cause confusion otherwise. It would be smart to not put some implementation detail like nbt into the name.

@lynxplay

lynxplay commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@Leguan16 the point of "primitive" here was that the persistent data type interface already has the concept of a complex and a primitive type. We can fight over the verb estimate but "storage" vs "primitive" seems like an easy choice in my head.

@Leguan16

Leguan16 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

what about getPrimitiveStorageType?

Since I assume you want the primitive to be apart of the method name, and we are getting the type the PDC is actually stored in i think its a good name.

@Machine-Maker

Copy link
Copy Markdown
Member

I think primitive is a good word to use. That is what we call it in when you are implementing PersistentDataType for a custom converter to your own type, we call the base type a getPrimitiveType.

@Keksnet

Keksnet commented Aug 6, 2026

Copy link
Copy Markdown
Author

I have renamed the method to getPrimitiveStorageType and added to the documentation that the returned type is estimated based on the "primitive type that is stored" as explation for the storage type.
Would that be fine for everyone involved here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

4 participants