From 93d7025ed27596ca39e6d94922c85297cbdd48b7 Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Sun, 16 Jun 2024 15:00:34 -0400 Subject: [PATCH] Add `AnnoyingFile#getSectionOrCreate(...)` --- .../xyz/srnyx/annoyingapi/file/AnnoyingFile.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java index 774dc2b..64389b4 100644 --- a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java +++ b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java @@ -186,6 +186,18 @@ public void save() { */ public void log(@NotNull Level level, @Nullable String key, @NotNull String message) { AnnoyingPlugin.log(level, ChatColor.getLastColors(message) + path + (key == null ? "" : ", " + key) + " | " + message); + + /** + * Gets the {@link ConfigurationSection} at the path or creates an empty one it if it doesn't exist + * + * @param path the path to the node + * + * @return the {@link ConfigurationSection} at the path or a new one if it doesn't exist + */ + @NotNull + public ConfigurationSection getSectionOrCreate(@NotNull String path) { + final ConfigurationSection section = getConfigurationSection(path); + return section == null ? createSection(path) : section; } /**