Custom Data and UUIDs

Using “fakeplayerdata” as a reference…

    public Optional<FakeData> from(DataContainer container) {
        if (!container.contains(FakeKeys.FAKE_STRING.getQuery(), FakeKeys.FAKE_BOOL.getQuery(), FakeKeys.FAKE_BOUNDED.getQuery())) {
            return Optional.empty();
        final String string = container.getString(FakeKeys.FAKE_STRING.getQuery()).get();
        final boolean bool = container.getBoolean(FakeKeys.FAKE_BOOL.getQuery()).get();
final int level = container.getInt(FakeKeys.FAKE_BOUNDED.getQuery()).get();

there is no container.getUUID() entry…
the only thing that I thought might lead in the right path was getClass() as in getClass(UUID.class) but then, it falls flat after that for me…

So what goes there?

And what about everywhere else – between the dataclass, immutabledataclass, and datamanipulatorbuilderclass classess, what code is required so that the UUID info is stored as persistant across boots and restored - aka, saved to file output not just memory, and read in from file input, not just memory (file input being wherever it is natively stored in my case, I’ll be attaching the UUID to a block-tile (ie chest or dispenser…)

Additionally, Lists of UUIDs, and what is required for the key methods to save the list out, and read back in into a list?

I have a system that is currently working that uses string-representations of UUID because when I last fought trying to make uuids work, the systems to work with uuids were in-the-works scrambled up and numerous experts tried to assist with funky code but even the hacky workarounds and ultimately ‘right’ approaches resulted in the UUIDs being read back in in reverse order ( a bug Im told has since been corrected)

I’ve got a customdata system that i use as a template, that was made by banging away at things and some input from people, and from a couple examples found before, but I’m told "its horrible, you’re doing so many things incorrectly " in abstract explanations, without actually pointing the way to fix the code, which as far as I can tell works absolutely perfectly in the plugins (except for warnings on bootup about not implimenting a method something about versioning) that I use the template on. is my custom data template that is using strings and I’d love to go native UUID for.

I have not been able to find actual code snips for dealing with UUID in any way, as a direct example to look at.

I would greatly appreciate remedying this.

I would even go as far as agreeing to pay someone via paypal to modify my entire set of classes to give the proper, absolutely-required, streamlined non-redundant/unnecessary code (such as mine is supposedly filled with) with proper ways to access given info (still with uuids in string form there is fine, to clean up what is there, and be a generic list-of-strings solution to add more concrete examples to the global knowledgebase and become a core starting template for other custom data.
{And then after that, we wait for a little while for gabizou to break the data API with a change that he announced he was planning to do the other day, and see how bad the aftermath will be }

From what I know, what you can do for UUIDs is to store them as a string, then revert them to a UUID with UUID#fromString(), as for persistent storage, your IDE may not notify you (Mine didn’t) but you need to override toContainer() in order to allow for storage to the playerdata that’s saved when the server shuts down

Sponge has a few different ways to serialize/deserialize objects.

  • If the object is a native/collection type, there’ll be a getX() method for you to use.

  • If the object is DataSerializable, then you use getSerializable() passing in the class. This will use the DataBuilder registered in DataManager to construct the object - which allows you to make your own custom serializable objects.

  • Otherwise, you can use getObject() - this will not work for all objects, instead it will fetch the DataTranslator for the object type registered in DataManager. This is similar to DataSerializable, but designed for objects outside of Sponge that still need to be persisted. You can see the full list here:

All of the methods also have a getXList() equivalent as well.

Of course, the final option is to make your own system which reads in the DataView, finds the necessary bits and constructs an object. But all that is already made and packaged up nicely for you with the methods in DataView and DataManager. Use em :wink:

Try #getObject(query, UUID.class). Simple Serializables like UUID can be used directly.

Alright, so that addresses what to go in the one spot for a single UUID, I’ll try a bit to analogously find the code for data flowing the other direction.

What about a list of UUIDs though, because its a list, but the data within the list isn’t the simple type. Solutions before (which I dont have anymore) involved doing some mapping or something into pieces that could be pieced into the list and vice-versa?

As I mentioned, there’s also a getObjectList(query, UUID.class) that will fetch a list of UUIDs.