don't delete all npc files before saving, instead just delete whenever the npc is deleted

This commit is contained in:
Pyrbu 2023-08-26 23:42:17 +02:00
parent e789fe2f9c
commit 197ffaa50b
3 changed files with 5 additions and 5 deletions

@ -142,9 +142,10 @@ public class NpcRegistryImpl implements NpcRegistry {
@Override
public void delete(String id) {
id = id.toLowerCase();
if (!npcIdLookupMap.containsKey(id)) return;
unregister(npcIdLookupMap.get(id));
NpcEntryImpl entry = npcIdLookupMap.remove(id.toLowerCase());
if (entry == null) return;
unregister(entry);
storage.deleteNpc(entry);
}
public void unload() {

@ -7,4 +7,5 @@ import java.util.Collection;
public interface NpcStorage {
Collection<NpcEntryImpl> loadNpcs();
void saveNpcs(Collection<NpcEntryImpl> npcs);
void deleteNpc(NpcEntryImpl npc);
}

@ -88,8 +88,6 @@ public class YamlStorage implements NpcStorage {
@Override
public void saveNpcs(Collection<NpcEntryImpl> npcs) {
File[] files = folder.listFiles();
if (files != null && files.length != 0) for (File file : files) file.delete();
for (NpcEntryImpl entry : npcs) try {
YamlConfiguration config = new YamlConfiguration();
config.set("id", entry.getId());