From c9a34de9e342523a82f7e85542c993dd24c573ed Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sun, 22 Oct 2023 16:53:56 +0200 Subject: [PATCH] add error handling to yaml storage loader (resolves #102) --- .../java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 0ce9aef..0bb08b8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -51,7 +51,7 @@ public class YamlStorage implements NpcStorage { File[] files = folder.listFiles(); if (files == null || files.length == 0) return Collections.emptyList(); List 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); UUID uuid = config.contains("uuid") ? UUID.fromString(config.getString("uuid")) : UUID.randomUUID(); NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, config.getString("world"), @@ -92,6 +92,9 @@ public class YamlStorage implements NpcStorage { entry.setSave(true); npcs.add(entry); + } catch (Throwable t) { + logger.severe("Failed to load npc file: " + file.getName()); + t.printStackTrace(); } return npcs; }