Skip to content

Commit

Permalink
Save config on screen replaced & destroy as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampflower committed Jan 17, 2023
1 parent 5f16f00 commit a49b095
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/kjp12/musicmoods/client/ConfigurationScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit a49b095

Please sign in to comment.