Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public boolean load() {
return false;
}

afterLoad();
// Allow configs to persist migrations/defaults during afterLoad().
safeToSave = true;
afterLoad();
return true;
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ public void saveOverwritesFileAfterSuccessfulReload() throws IOException {
assertTrue("File should contain modified value", fileContent.contains("modifiedValue"));
}

@Test
public void saveInAfterLoadPersistsChanges() throws IOException {
File configFile = new File(temporaryFolder.getRoot(), "self-save.yml");
try (FileWriter writer = new FileWriter(configFile)) {
writer.write("key: originalValue\n");
}

CommonLogger logger = new TestLogger();
SelfSavingTestConfig config = new SelfSavingTestConfig(temporaryFolder.getRoot(), configFile, logger);

assertTrue("Load should succeed for valid YAML", config.load());

String fileContent = new String(Files.readAllBytes(configFile.toPath()));
assertTrue("afterLoad() save should persist updated value", fileContent.contains("updatedInAfterLoad"));
}

/**
* Test config that tracks save behavior
*/
Expand All @@ -263,4 +279,24 @@ public void onSave() {
// No-op
}
}

/**
* Test config that mutates and saves during afterLoad.
*/
private static class SelfSavingTestConfig extends Config {
public SelfSavingTestConfig(File dataFolder, File file, CommonLogger logger) {
super(dataFolder, file, logger);
}

@Override
public void afterLoad() {
conf.set("key", "updatedInAfterLoad");
save();
}

@Override
public void onSave() {
// No-op
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ public IpRangeUnbanEvent(IpRangeBanData ban, PlayerData actor, String reason, bo
this.reason = reason;
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ public IpUnbanEvent(IpBanData ban, PlayerData actor, String reason, boolean sile
this.reason = reason;
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ public IpUnmutedEvent(IpMuteData mute, PlayerData actor, String reason, boolean
this.reason = reason;
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ public NameUnbanEvent(NameBanData ban, PlayerData actor, String reason, boolean
this.reason = reason;
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ public PlayerUnbanEvent(PlayerBanData ban, PlayerData actor, String reason, bool
this.reason = reason;
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ public PlayerUnmuteEvent(PlayerMuteData mute, PlayerData actor, String reason, b
this.reason = reason;
}
}