Configuration changes aren't applied until client/server restarts
endorh opened this issue ยท 4 comments
Hi, I'm the developer of Simple Config. Recently, someone in my Discord server brought to me an issue around supporting multiple config files to support Zombie Awareness's config setup.
They mentioned they'd tried using your mod to bind a command to some configuration changes, but those changes weren't applying until the next server restart.
In order to help them, I tried quickly checking your mod to see if I could help them get it to work, but I found instead that your mod wasn't reloading the configs properly. Since I already faced this problem when making my own mod, I thought I'd as well let you know how I did it, and why your current implementation doesn't work.
The /reload
command you use in ChangeModeCommand:80
is a vanilla command that reloads datapacks. Unfortunately, it does nothing to reload Forge's config files.
What you need to reload Forge's config files is triggering a ModConfigEvent.Reloading
event for the mod config in question. Unfortunately, this event has a private constructor in Forge (at least it was back in 1.16), so you need to use reflection to trigger it.
Feel free to use the approach I used in SimpleConfigNetworkHandler:203
. The key parts are the tryFireEvent
and the newReloading
methods. I prepare all the reflection objects necessary in a static
initializer, but there are many other ways to do it.
Config reloading is done in the ApplyMode function here:
Oh, my bad, it seems I didn't look deep enough.
Apparently, the error was in the other mod in the end, sorry for the inconvenience ๐
Hey @endorh I got a report that showed the error. I was trying to reflect into the wrong class.
At least in 1.19.2 reflection seems to be entirely unnecessary now.
See here how you can fire the event: