How to Modify Config Using Command?

Hello! I’ve been trying to modify my plugins config using a sub-command. The plugin loads fine. But when I try to execute my sub-command (/kit add) with the arguments, it returns an error. In addition, when I try to run my command without a sub-command, it tells me the arguments I have provided are not a valid sub-command.

My code is on GitHub, which you can view here.
The error can be viewed here.

Any and all help would be extremely appreciated! Thanks!

The problem is in your Utils class.
You cannot use @Inject in it, dependency injection will only work in the @Plugin main class.
I recommend making your plugin a singleton, with a public static Main getInstance() method, then call Main.getInstance().configManager... in Utils (line 25 in this case).

1 Like

Alright. I’ll try it! :smiley: Also, you originally posted that ZML said in the IRC that it was possible to set a command with a no-args fallback, by marking the ChildCommandExecutorElement as optional. How would I do that?

Thanks for the help so far! Sadly, now that it’s working, it’s erasing the whole config when it saves. Is there anyway so that it simply adds a node rather than replacing the whole config with just that node?

Make sure you save the config after modifying the nodes.

1 Like

I just had a thought.

If most plugins use Configurate, and most people would be insane to not write validation code for the configs that get loaded, if you put that validation code in a re-useable method, you could both use it to error on load, AND to parse and validate input in chat…

So theoretically, it wouldn’t be hard to implement a config editor command library, that allows people to tweak your config using the known DataQuery/DataPaths and create/add / read/list / update/insert/reorder / delete commands that will work with the known basic configurate datatypes.

Anyone keen to give it a go? Maybe if it works good enough it could be intergrated into SpongeAPI?

Works beautifully now!

What is the overall goal for this? What’s the use case?