From e789fe2f9c3080e5dfe81082bafe3b18a90f1ae0 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 26 Aug 2023 23:41:40 +0200 Subject: [PATCH] print stack traces of save errors instead of rethrowing --- .../znpcsplus/storage/yaml/YamlStorage.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 27e8186..5c393a3 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 @@ -19,12 +19,14 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; -import java.io.IOException; import java.util.*; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; public class YamlStorage implements NpcStorage { + private final static Logger logger = Logger.getLogger("YamlStorage"); + private final PacketFactory packetFactory; private final ConfigManager configManager; private final ActionRegistry actionRegistry; @@ -118,12 +120,22 @@ public class YamlStorage implements NpcStorage { .filter(Objects::nonNull) .collect(Collectors.toList())); - config.save(new File(folder, entry.getId() + ".yml")); - } catch (IOException e) { - throw new RuntimeException(e); + config.save(fileFor(entry)); + } catch (Exception e) { + logger.severe("Failed to save npc with id " + entry.getId()); + e.printStackTrace(); } } + @Override + public void deleteNpc(NpcEntryImpl npc) { + fileFor(npc).delete(); + } + + private File fileFor(NpcEntryImpl entry) { + return new File(folder, entry.getId() + ".yml"); + } + public NpcLocation deserializeLocation(ConfigurationSection section) { return new NpcLocation( section.getDouble("x"),