From a49b095cddef5e6ee0addb8767126d51828b4186 Mon Sep 17 00:00:00 2001 From: KJP12 Date: Tue, 17 Jan 2023 09:07:57 -0600 Subject: [PATCH] Save config on screen replaced & destroy as well --- .../musicmoods/client/ConfigurationScreen.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/net/kjp12/musicmoods/client/ConfigurationScreen.java b/src/main/java/net/kjp12/musicmoods/client/ConfigurationScreen.java index c094372..c780614 100644 --- a/src/main/java/net/kjp12/musicmoods/client/ConfigurationScreen.java +++ b/src/main/java/net/kjp12/musicmoods/client/ConfigurationScreen.java @@ -40,6 +40,8 @@ public class ConfigurationScreen extends SpruceScreen { private SpruceTabbedWidget tabbedWidget; + private boolean committed; + public ConfigurationScreen(final Screen parent) { super(Component.translatable("music-moods.gui.configuration")); this.parent = parent; @@ -62,9 +64,21 @@ protected void init() { Constants.buttonWidth, Constants.buttonHeight, SpruceTexts.GUI_DONE, btn -> onClose())); } + @Override + public void removed() { + if (!committed) { + try { + Config.commit(); + } catch (IOException ioe) { + logger.error("Failed to save Music-Moods config. User not notified.", ioe); + } + } + } + @Override public void onClose() { try { + committed = true; Config.commit(); minecraft.setScreen(parent); } catch (IOException ioe) {