Skip to content

Commit

Permalink
Adjust AnnoyingFile#load()
Browse files Browse the repository at this point in the history
Now checks `#canBeEmpty()`
  • Loading branch information
srnyx committed Dec 11, 2022
1 parent 1ffb5e7 commit 8107c31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingData.java
Expand Up @@ -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();
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 8107c31

Please sign in to comment.