From 8107c318bb3f4fb83f89497afad72fac22edf4f3 Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Sat, 10 Dec 2022 19:46:08 -0500 Subject: [PATCH] Adjust `AnnoyingFile#load()` Now checks `#canBeEmpty()` --- .../xyz/srnyx/annoyingapi/file/AnnoyingData.java | 2 +- .../xyz/srnyx/annoyingapi/file/AnnoyingFile.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingData.java b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingData.java index ab6c2bb..0a0d993 100644 --- a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingData.java +++ b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingData.java @@ -29,7 +29,7 @@ public class AnnoyingData extends YamlConfiguration implements AnnoyingFile { */ public AnnoyingData(@NotNull AnnoyingPlugin plugin, @NotNull String path, boolean canBeEmpty) { this.path = path; - this.file = new File(new File(plugin.getDataFolder(), "data"), path); + this.file = new File(plugin.getDataFolder(), "data/" + path); this.canBeEmpty = canBeEmpty; load(); } diff --git a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java index f9d28af..16a0816 100644 --- a/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java +++ b/src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java @@ -51,10 +51,18 @@ public interface AnnoyingFile { */ default void load() { final File file = getFile(); - if (!file.exists()) create(); + + // Create the file if it doesn't exist and it can be empty + if (canBeEmpty() && !file.exists()) { + create(); + } else if (!file.exists()) { + return; + } + + // Load try { getYaml().load(file); - } catch (IOException | InvalidConfigurationException e) { + } catch (final IOException | InvalidConfigurationException e) { e.printStackTrace(); } }