event based rewrite

small core with everything going through events
we should make this "atomic" (write it to a temp file, something like `./state/plugin.json.temp` and then rename it to the intended path