Skip to content
Merged
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
59 changes: 31 additions & 28 deletions commons/src/main/java/net/swofty/commons/config/ConfigProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@

public class ConfigProvider {

@Getter
@Setter
@Accessors(fluent = true)
private static Settings settings;

static {
try {
Logger.info("Loading config...");
YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
.path(Path.of("./configuration/config.yml"))
.nodeStyle(NodeStyle.BLOCK)
.build();

CommentedConfigurationNode node = loader.load();
Settings existingSettings = node.get(Settings.class);
if (existingSettings == null) {
existingSettings = new Settings();
}
Settings config = existingSettings;
node.set(Settings.class, config);
loader.save(node);

settings(config);
} catch (IOException e) {
throw new RuntimeException("Failed to load configuration", e);
}
}
}
@Getter
@Setter
@Accessors(fluent = true)
private static Settings settings;

static {
try {
Logger.info("Loading config...");

YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
.path(Path.of("./configuration/config.yml"))
.nodeStyle(NodeStyle.BLOCK)
.build();

CommentedConfigurationNode root = loader.load();
CommentedConfigurationNode defaults = loader.createNode();
defaults.set(Settings.class, new Settings());
root.mergeFrom(defaults);

Settings loaded = root.get(Settings.class);
if (loaded == null) {
loaded = new Settings();
}

loader.save(root);
settings(loaded);
} catch (IOException e) {
throw new RuntimeException("Failed to load configuration", e);
}
}
}