Skip to content

Commit bae6a21

Browse files
committed
Let yaml data files load later.
1 parent be02abd commit bae6a21

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package community.leaf.configvalues.bukkit.data;
2+
3+
public enum Load
4+
{
5+
NOW,
6+
LATER
7+
}

config-values-bukkit/src/main/java/community/leaf/configvalues/bukkit/data/YamlDataFile.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@ public class YamlDataFile implements UpdatableYamlDataSource
4545

4646
public YamlDataFile(Path directoryPath, String name)
4747
{
48-
this(directoryPath, name, Throwable::printStackTrace);
48+
this(directoryPath, name, Load.NOW);
4949
}
5050

51-
public YamlDataFile(Path directoryPath, String name, Consumer<Exception> exceptions)
51+
public YamlDataFile(Path directoryPath, String name, Load load)
52+
{
53+
this(directoryPath, name, load, Throwable::printStackTrace);
54+
}
55+
56+
public YamlDataFile(Path directoryPath, String name, Load load, Consumer<Exception> exceptions)
5257
{
5358
this.filePath = directoryPath.resolve(name);
5459
this.data = new YamlConfiguration();
5560
this.exceptions = exceptions;
5661

57-
reload();
62+
if (load == Load.NOW) { reload(); }
5863
}
5964

6065
public Path getFilePath() { return filePath; }
@@ -81,7 +86,8 @@ public YamlDataFile(Path directoryPath, String name, Consumer<Exception> excepti
8186
protected void reloadsWith(Runnable reloadHandler)
8287
{
8388
this.reloadHandler = Objects.requireNonNull(reloadHandler, "reloadHandler");
84-
reloadHandler.run();
89+
if (isLoaded) { reloadHandler.run(); }
90+
else { reload(); } // reload handler is called in reload
8591
}
8692

8793
public final void reload()

0 commit comments

Comments
 (0)