I have been reading about Data API and how to use it for custom data. It seems pretty easy to use, actually… If I were making a typical plugin.
However, I’m attempting to do scripting (Lua, based on Rembulan). I want scripts to be able to save data to Sponge objects as if they were Lua tables (kinda like Maps in Java). Using data manipulators doesn’t seem very good for this. I thought about raw data… Which is apparently not implemented at all.
Is there any way around this, or should I just use NMS NBT?
If you absolutely 100% want to have arbitrary NMS-like structures, use
ConfigurationNodes, which are data-translatable.
From the docs:
Objects with a registered DataTranslator can be retrieved using getObject(DataQuery, Class) or getObjectList(DataQuery, Class). A full list of classes that are supported by default can be found in DataTranslators.
The translator for
ConfigurationNodes is here: https://jd.spongepowered.org/5.0.0/org/spongepowered/api/data/persistence/DataTranslators.html#CONFIGURATION_NODE
I assume this would mean that I register one custom data manipulator (and associated stuff), then have ConfigurationNode in it. Sounds very good, and definitely better than any database/flatfile garbage I had to work with Skript on Bukkit…
Thanks for fast response!
Yeah, that would be the idea. I feel like just using a map data structure kind of oversimplifies the data API, but I can’t offer any alternatives, since I don’t know anything about lua
Well, in my experience having a good custom data storage is absolutely mandatory for a scripting language. I think part of Skript’s popularity is coming from the fact that you don’t need to think about how you save the data; instead, you just set a variable and it will (hopefully) be there next time you are checking for it.
And since Lua doesn’t have classes… Pretty much everything that is not a string or number or function is a table, or (if it is “userdata”), looks like a table to scripter.