Repository navigation
Add PersistentDataKey API - #14337
Conversation
|
Also, I am open to renaming suggestions. Feel free to suggest better naming for the two classes and static methods on the current |
|
Why would the key's generic need to track primitive type? I thought the primitive generic was more for enforcing implementation consistency of the primitive type in all the methods than for outside consumers |
Actually good catch. I just copied the semantics of the |
|
I am thinking about merging the distinct The NK class already extends Key. My idea behind this was to encourage developers to use Adventure Key (AK) over NK, but if NK is exposed over the API anyways, there's really no advantage, even if we wanted to switch to only AK (which I am not aware of.) I will tend to this in the evening. |
|
Could we look into actually registering these |
|
I've tended to the review comments and my previous comment about removing the distinct getKey/getNamespacedKey methods. I don't think it makes sense to poke into the PDC internals to register these PDK classes... the way it works right now is more than enough, IMO |
SirYwell
left a comment
There was a problem hiding this comment.
The asymmetry of passing Key and getting NamespacedKey is a bit weird but might be fine. If you want to keep that as an internal detail, you could just return Key but cast in the relevant places, although I'm not sure if that's a great solution.
|
The asymmetry is a by-product of wanting to promote Key usage in API, but everything in PDC wanting a namespaced key. If I'd wanted to completely hide it to the outside, I could do that by making the implementation on PDC/PDCV an implementation detail as well, instead of just using |
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@b3c6bcb8 Sync latest Moonrise changes PaperMC/Paper#14367 PaperMC/Paper@65ba9855 Allow unrestricting commands PaperMC/Paper#14358 PaperMC/Paper@e8750e1c [ci/skip] Resolve Schrödinger's accessor in HumanEntity starvation API PaperMC/Paper#14364 PaperMC/Paper@8097898e Refresh learnable recipes on recipe changes PaperMC/Paper#14302 PaperMC/Paper@615e915d Document undefined tracker behavior in track/untrack events. PaperMC/Paper#14189 PaperMC/Paper@16db2422 Add PersistentDataKey API PaperMC/Paper#14337
This PR introduces a new class to the PDC group:
PersistentDataKey<C>. This class act as an intersection type of both aPersistentDataType<?, C>and aNamespacedKey.Example code for testing and usage:
Click to expand
Why?
The purpose of this addition is to have an API-native way to store the access key and data type of a PDC value in one place. Traditionally, a plugin developer will have to keep track of the key and the data type separately, which may cause accidental errors not caught at compile time due to incorrect data type usage, or may generally not be nice to work with.
Why Key over NamespacedKey?
The Adventure Key class is nicer to use than NamespacedKey. New API typically always uses Key. In a PR that aimed to refactor PDC to use Key instead, the change was denied due to bytecode incompatibility. This, however, it not a problem for newly added classes or methods.
The implementation,
PaperPersistentDataKeyactually still usesNamespacedKey, as it can be cast toKeywithout any complications, which for as long asNamespacedKeystays the primary key class for PDC, needs to be exposed.Final notes
As with all my PRs, the implementation I have provided here is purely after what I thought was most fitting at the moment. I am open to improvement suggestions and critique on this addition.