Skip to content

Commit e7de197

Browse files
committed
fix: make MoulConfigEditor properly call #saveNow
1 parent 9aaf518 commit e7de197

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

common/src/main/java/io/github/notenoughupdates/moulconfig/gui/CloseEventListener.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ interface CloseEventListener {
1717
* Called just before a voluntary close. Return [CloseAction.DENY_CLOSE] to override the close. Make sure to update
1818
* your state such that the user can close the gui afterward.
1919
*/
20-
fun onBeforeClose(): CloseAction
20+
fun onBeforeClose(): CloseAction = CloseAction.NO_OBJECTIONS_TO_CLOSE
2121

2222
/**
2323
* Called after the gui has been closed, both by the component gui, or by other actors, such as a teleport packet.
2424
*/
25-
fun onAfterClose()
26-
}
25+
fun onAfterClose() = Unit
26+
}

common/src/main/java/io/github/notenoughupdates/moulconfig/gui/MoulConfigEditor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import java.util.stream.Collectors;
5252

5353

54-
public class MoulConfigEditor<T extends Config> extends GuiElement {
54+
public class MoulConfigEditor<T extends Config> extends GuiElement implements CloseEventListener {
5555
private final long openedMillis;
5656
private final LerpingInteger optionsScroll = new LerpingInteger(0, 150);
5757
private final LerpingInteger categoryScroll = new LerpingInteger(0, 150);
@@ -1155,11 +1155,14 @@ private void handleKeyboardPresses() {
11551155
if (target.getTarget() >= 0) {
11561156
target.setTarget(Math.max(0, target.getTarget() - 5));
11571157
}
1158-
} else if (IMinecraft.INSTANCE.isKeyboardKeyDown(IMinecraft.INSTANCE.getKeyboardConstants().getEscape())) {
1159-
getConfigObject().saveNow();
11601158
}
11611159
}
11621160

1161+
@Override
1162+
public void onAfterClose() {
1163+
getConfigObject().saveNow();
1164+
}
1165+
11631166
public boolean goToOption(@NotNull ProcessedOption option) {
11641167
if (!setSelectedCategory(option.getCategory())) {
11651168
search("");

0 commit comments

Comments
 (0)