Save plugin storage when plugins are reloaded, if dirty

This commit is contained in:
ceikry 2023-08-19 16:50:30 -05:00
parent 3e45689d6e
commit 3fb709b098
2 changed files with 14 additions and 7 deletions

View file

@ -47,6 +47,7 @@ public class PluginRepository {
API.registeredMouseListeners.clear(); API.registeredMouseListeners.clear();
API.registeredKeyListeners.clear(); API.registeredKeyListeners.clear();
loadedPlugins.clear(); loadedPlugins.clear();
SaveStorage();
Init(); Init();
} }
@ -69,13 +70,7 @@ public class PluginRepository {
} catch (Exception e) {e.printStackTrace();} } catch (Exception e) {e.printStackTrace();}
} }
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(PluginRepository::SaveStorage));
try(FileOutputStream fos = new FileOutputStream(GlobalJsonConfig.instance.pluginsFolder + File.separator + "plsto")) {
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(PluginRepository.pluginStorage);
oos.close();
} catch (Exception e) {e.printStackTrace();}
}));
try { try {
URL[] classPath = {pluginsDirectory.toURI().toURL()}; URL[] classPath = {pluginsDirectory.toURI().toURL()};
@ -183,4 +178,15 @@ public class PluginRepository {
public static void OnLogin() { public static void OnLogin() {
loadedPlugins.values().forEach((plugin) -> plugin.OnLogin()); loadedPlugins.values().forEach((plugin) -> plugin.OnLogin());
} }
public static void SaveStorage() {
if (pluginStorage.containsKey("_keystoreDirty")) {
pluginStorage.remove("_keystoreDirty");
try(FileOutputStream fos = new FileOutputStream(GlobalJsonConfig.instance.pluginsFolder + File.separator + "plsto")) {
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(PluginRepository.pluginStorage);
oos.close();
} catch (Exception e) {e.printStackTrace();}
}
}
} }

View file

@ -242,6 +242,7 @@ public class API {
public static void StoreData(String key, Object value) { public static void StoreData(String key, Object value) {
PluginRepository.pluginStorage.put(key, value); PluginRepository.pluginStorage.put(key, value);
PluginRepository.pluginStorage.put("_keystoreDirty", true);
} }
public static Object GetData(String key) { public static Object GetData(String key) {