Okay, so there are a couple questions here.
First, you can inject your PluginContainer as you’ve shown just fine (if that’s within your @Plugin class), but you don’t have to. You can get the container for any plugin using Sponge.getPluginManager.getPlugin(id) (which returns an Optional<PluginContainer>, which is why it’s recommended to have in injected for you. What I personally do is inject it into the constructor of my @Plugin class (like this) - so you have a couple of options to work with.
Onto the AssetManager. The largest thing to know about how the AssetManager works is that it’s just a basic tool for getting a resource from your plugin (see ClassLoader#getResource). An asset is simply a wrapper around the URL returned by this method and provides a couple utility functions for working with them, but it is not in itself a file. The AssetManger is more particular, however, in that it can only read files from your assets folder - specifically assets/pluginid, which go in the resources folder (src/main/resources).
So, to answer your first question, should you check if the file does not exist first? Yes, however it can be done for you. The Files#copy method will throw an exception if the file exists and you have not indicated you wish to replace it. Thankfully, the Asset#copyToFile method allows you to specify if you would like to overwrite the file or only copy it if it does not exist (which is what you want for a default config). You should be able to accomplish what you need with:
plugin.getAsset("default.conf").get().copyToFile(configPath, false, true);
// where "default.conf" is the name of the file in your assets folder
// configPath is the path to the destination of the file
// 'false' states that an existing file should be overwritten
// `true` states that it should only be copied if the file does not exist.
With your final message, remember that getAsset returns an Optional<Asset>, not the asset itself. You need to call .get() first before calling any other methods (or however else you’d like to work with it). I simply call .get() because if I’m missing an asset then I have other issues xD
With that being said, here are the two main answer to your questions:
- An
Assetis a file that is stored in your jar underresources/assets/pluginid. - You need to check (directly or indirectly) if the file exists and handle that appropriately. You can do that yourself or delegate it to the
copyToFilemethod; your choice.
If you’d like an example, you can take a look at the ActiveTime configuration (which has been a bit encapsulated) and it’s assets folder.