My understanding is that save state should be called only ONCE when a plugin is uninstalled.
It is possible, although unlikely that a plugin will change its state during the OnPluginSaveState callback. Thus if this function is called a second time during plugin save state, a different, and perhaps unwanted state would be saved. This is precisely what happens in my plugin.
I allow user 'plugins' to be added to my own plugin. A list of current plugins is stored in an table, so that the same plugins can be loaded next timer. In the OnPluginSaveState function, each plugin is uninstalled, giving it a chance to save it's own state. The list of plugins is serialized before the plugins are uninstalled. However, by the end of the OnPluginSaveState function, the table which holds current plugins is empty, since all plugins have technically been removed. Thus when OnPluginSaveState is called for a second time, the empty table is serialized, and on restarting MUSHclient, none of the appropriate plugins are loaded by my plugin.
It would be easy enough for me to change it so that the state was not changed during the course of OnPluginSaveState. However, doing some testing, I have found that upon closing MUSHclient, OnPluginSaveState appears to be called once. If the 'some world variables have changed... do you wish to save..?' dialog pops up, on clicking yes, state is saved again for the plugins, and it appears that perhaps the save state fuction is called a third time somewhere else during the close process, although I am not sure about the last one.
It is possible, although unlikely that a plugin will change its state during the OnPluginSaveState callback. Thus if this function is called a second time during plugin save state, a different, and perhaps unwanted state would be saved. This is precisely what happens in my plugin.
I allow user 'plugins' to be added to my own plugin. A list of current plugins is stored in an table, so that the same plugins can be loaded next timer. In the OnPluginSaveState function, each plugin is uninstalled, giving it a chance to save it's own state. The list of plugins is serialized before the plugins are uninstalled. However, by the end of the OnPluginSaveState function, the table which holds current plugins is empty, since all plugins have technically been removed. Thus when OnPluginSaveState is called for a second time, the empty table is serialized, and on restarting MUSHclient, none of the appropriate plugins are loaded by my plugin.
It would be easy enough for me to change it so that the state was not changed during the course of OnPluginSaveState. However, doing some testing, I have found that upon closing MUSHclient, OnPluginSaveState appears to be called once. If the 'some world variables have changed... do you wish to save..?' dialog pops up, on clicking yes, state is saved again for the plugins, and it appears that perhaps the save state fuction is called a third time somewhere else during the close process, although I am not sure about the last one.