Custom Data in one plugin, now need elsewhere

Question for the Devs and those who are really good at the custom-data stuff, or anyone who has actually made a working solution demonstration of my exact problem and knows what they’re sayin :slight_smile:

Note - we’re talking me on my server only, my plugins are for my own server, no one elses, compatibility issues are for my own server to deal with, my production server will be a spongevanilla not forge and never have other mods to worry about) I have total control over how these mechanisms get used on my systems.

So a while back I made a plugin that attaches custom-data representing a lock-ownership and property flag to specific tile data (chests, furnaces, dispensers, jukeboxes, etc) to limit access to the containers to the player who is the owner. Now, after some time working on other plugins, I got an inspiration for an idea to impliment in a new plugin but which

This new plugin will end up as a result of what it does, create a dispenser or jukebox or chest block not sure which yet, on the BEHALF of the player – ie, the player will place a block somewhere containing ‘nanobots’ that will create a larger structure in a series of animations over a few seconds, and this structure will contain one of those chest/jukebox/dispenser blocks. I would still want this block to be locked in the same way as player-placed blocks in my lock plugin, and it seems a horrible shame to either have to :

    1. redundantly copy all the same data classes and implimentation from the other plugin and rename it to a different thing, and redundantly test every container interaction for this specific locked data - thereby having two plugins checking for two different types of the exact same thing redundantly… (“I didn’t cancel the event in plugin A because the data isn’t there, but in plugin B it is, so lets cancel it, with all the redundant handling and messages copied from plugin A”)
    1. create this new plugin code all within the exact same plugin as my lock plugin making a superplugin AB

The custom data, when offered and gotten from the map Location, is stored in the map nbt per that plugin. Compartmentalized by sponge per plugin.

What (better) options do I have here – all I need is for plugin B to create the lock data for one block, that it can associate to the user making ‘the machine’ instead of directly placing as my lock plugin is picking up on – and once that lock data is made by this plugin B, I can let plugin A take care of all the handling and operation on it as it would with any other lockable block.

I’m not beyond the point of putting that custom data somewhere else, in some other way, if sponge will let it be cross-plugin accessed – I can wipe the map on my playtest server and start anew. I just want to use the internal custom-data aspect that saves it ‘integrated’ with map data, and test for data presence – I dont want to change my method of storing information to be for example, scrapping data storage and go to a database – sure, that would be easy for plugin B to hook into the table for plugin A, I know that will work. I want to try to operate within the scope of the custom-data /server-file integration level.

IS IT possible to cross-plugin share the same custom data at all, or does sponge compartmentalize plugin-data entirely and in no way permit crossing?

I believe that any plugin can access custom data once it has been assigned.

@Flibio is correct. Data is stored on the block, and a get() method does not know what plugin is asking for it. Also, in your class that extends some form of AbstractData, remember to @Override the toContainer() method to set how data will be stored to disk.

So how do i put that same data stuff into plugin B?
Just copy the class files from plugin A project into plugin B project? The classes are stored in a package subset package of my pluginA – a.b.c.pluginA.custom.lockdata for example. Would they need to remain that way in pluginB, or make a different package in A that is independant of the plugin project ?

Is there a better way to make them common to both plugins, so that if I have to modify something, its done to both the same way for-sure?

The data may be accessable by any plugin, but that data is tied to the plugin in terms of the nbt serializing/deserialzing… so if i copy the code into a new project package, the fully qualified classname changes

You would want to make Plugin B depend on Plugin A. Make sure Plugin A loads before Plugin B.

It’s just a dependency on that plugin much like you already depend upon SpongeAPI, you just need to ensure that it’s in your annotations or mcmod info as a dependency to make sure that things that depend on it load afterwards.

If you really want, you could factor out your custom data classes into their own plugins, so you don’t need to depend on the whole plugin, but considering this is for your private server, it’s probably overkill.

Alright, thanks guys. And thanks for the clarification, ryan. I’ll give it a try.