Skip to content

Commit 0ad5850

Browse files
committed
Fixed config getting reset when corrupted
1 parent 010a423 commit 0ad5850

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Plugin/src/main/java/dev/lrxh/neptune/providers/manager/IService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class IService {
1919
public abstract void save();
2020

2121
public <T extends ConfigData> void saveAll(String root, Collection<T> items, Function<T, String> keyFn) {
22+
if (Neptune.get().isErrored()) return;
2223
FileConfiguration config = getConfigFile().getConfiguration();
2324
config.set(root, null);
2425
for (T item : items) item.write(config.createSection(root + "." + keyFn.apply(item)));

Plugin/src/main/java/dev/lrxh/neptune/utils/ConfigFile.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.lrxh.neptune.Neptune;
44
import lombok.Getter;
5+
import org.bukkit.configuration.InvalidConfigurationException;
56
import org.bukkit.configuration.file.YamlConfiguration;
67

78
import java.io.File;
@@ -36,7 +37,13 @@ public ConfigFile(String name) {
3637
}
3738
}
3839

39-
this.configuration = YamlConfiguration.loadConfiguration(this.file);
40+
this.configuration = new YamlConfiguration();
41+
try {
42+
this.configuration.load(this.file);
43+
} catch (IOException | InvalidConfigurationException e) {
44+
ServerUtils.error("Failed to load '" + name + ".yml'" + e);
45+
Neptune.get().setErrored();
46+
}
4047
}
4148

4249
public void save() {

0 commit comments

Comments
 (0)