add error handling to yaml storage loader (resolves #102)

This commit is contained in:
Pyrbu 2023-10-22 16:53:56 +02:00
parent 11b81ba5fc
commit c9a34de9e3

@ -51,7 +51,7 @@ public class YamlStorage implements NpcStorage {
File[] files = folder.listFiles(); File[] files = folder.listFiles();
if (files == null || files.length == 0) return Collections.emptyList(); if (files == null || files.length == 0) return Collections.emptyList();
List<NpcEntryImpl> npcs = new ArrayList<>(files.length); List<NpcEntryImpl> npcs = new ArrayList<>(files.length);
for (File file : files) if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) { for (File file : files) if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file); YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
UUID uuid = config.contains("uuid") ? UUID.fromString(config.getString("uuid")) : UUID.randomUUID(); UUID uuid = config.contains("uuid") ? UUID.fromString(config.getString("uuid")) : UUID.randomUUID();
NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, config.getString("world"), NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, config.getString("world"),
@ -92,6 +92,9 @@ public class YamlStorage implements NpcStorage {
entry.setSave(true); entry.setSave(true);
npcs.add(entry); npcs.add(entry);
} catch (Throwable t) {
logger.severe("Failed to load npc file: " + file.getName());
t.printStackTrace();
} }
return npcs; return npcs;
} }