Skip to content

Commit

Permalink
feat: add WorldSettings.WorldSetting#runtimeOnly, If set this to tr…
Browse files Browse the repository at this point in the history
…ue, the information of this world will not be saved to world-settings.yml, therefore it won't be loaded after the server restarted. This is useful for world created for game room by plugin and will be deleted when shutdown.
  • Loading branch information
smartcmd committed Jan 22, 2025
1 parent d0818ff commit c6da52c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Added multiple `BlockUpdateService#scheduleRandomBlockUpdate` method overloads, which can schedule a random block
update at a specified position. These methods are used by fire block currently to make it able to change fire spreading
speed by changing random block update speed.
- (API) Added `WorldSettings.WorldSetting#runtimeOnly`, If set this to true, the information of this world will not be saved
to world-settings.yml, therefore it won't be loaded after the server restarted. This is useful for world created for game
room by plugin and will be deleted when shutdown.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions api/src/main/java/org/allaymc/api/world/WorldSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ public class WorldSettings extends OkaeriConfig {
@Accessors(fluent = true)
public static class WorldSetting extends OkaeriConfig {
@Setter
@Comment("If set to false, the world will not be loaded")
@CustomKey("enable")
@Builder.Default
private boolean enable = true;

@Setter
@Comment("If set to true, the information of this world will not be saved to world-settings.yml,")
@Comment("therefore it won't be loaded after the server restarted. This is useful for world created")
@Comment("for game room by plugin and will be deleted when shutdown")
@CustomKey("runtime-only")
private boolean runtimeOnly;

@CustomKey("storage-type")
private String storageType;
private DimensionSettings overworld;

@Comment("If you don't want to have nether / the end in this world, left it null")
private DimensionSettings nether;

@CustomKey("the-end")
private DimensionSettings theEnd;

Expand All @@ -59,6 +70,7 @@ public static class DimensionSettings extends OkaeriConfig {
@CustomKey("generator-type")
@Builder.Default
private String generatorType = "VOID";

@CustomKey("generator-preset")
@Builder.Default
private String generatorPreset = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ public void loadWorld(String name, WorldSettings.WorldSetting setting) {

if (addWorld(world)) {
log.info(I18n.get().tr(TrKeys.A_WORLD_LOADED, name));
if (!worldConfig.worlds().containsKey(name)) {
worldConfig.worlds().put(name, setting);
worldConfig.save();
if (setting.runtimeOnly() || worldConfig.worlds().containsKey(name)) {
// Runtime only world won't be saved to world-settings.yml
return;
}
worldConfig.worlds().put(name, setting);
worldConfig.save();
}
}

Expand Down

0 comments on commit c6da52c

Please sign in to comment.