From 47fc78469b5b7b4840a48633bfae5c8f28d2174e Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 4 Sep 2012 19:59:46 +0800 Subject: [PATCH] Don't overwrite saves file if it failed to load --- src/main/java/net/citizensnpcs/Citizens.java | 9 ++++++++- .../net/citizensnpcs/npc/entity/CitizensHumanNPC.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 9f9350b07..fdb295f7b 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -194,6 +194,12 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { config = new Settings(getDataFolder()); setupStorage(); + if (!saves.load()) { + saves = null; + Messaging.severeF("Unable to load saves, disabling..."); + getServer().getPluginManager().disablePlugin(this); + return; + } npcRegistry = new CitizensNPCRegistry(saves); traitFactory = new CitizensTraitFactory(); @@ -270,6 +276,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } public void save() { + if (saves == null) + return; for (NPC npc : npcRegistry) ((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId())); @@ -292,7 +300,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { // TODO: refactor private void setupNPCs() { - saves.load(); int created = 0, spawned = 0; for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { int id = Integer.parseInt(key.name()); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java index 4c742eca8..1fa05fdf8 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensHumanNPC.java @@ -35,7 +35,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable { // set the head yaw in another tick - if done immediately, // minecraft will not update it. } - }, 1); + }, 5); handle.getBukkitEntity().setSleepingIgnored(true); return handle; }