Don't overwrite saves file if it failed to load

This commit is contained in:
fullwall 2012-09-04 19:59:46 +08:00
parent f75b33dfce
commit 76e954f2f2
2 changed files with 9 additions and 2 deletions

View File

@ -194,6 +194,12 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
config = new Settings(getDataFolder()); config = new Settings(getDataFolder());
setupStorage(); setupStorage();
if (!saves.load()) {
saves = null;
Messaging.severeF("Unable to load saves, disabling...");
getServer().getPluginManager().disablePlugin(this);
return;
}
npcRegistry = new CitizensNPCRegistry(saves); npcRegistry = new CitizensNPCRegistry(saves);
traitFactory = new CitizensTraitFactory(); traitFactory = new CitizensTraitFactory();
@ -270,6 +276,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
} }
public void save() { public void save() {
if (saves == null)
return;
for (NPC npc : npcRegistry) for (NPC npc : npcRegistry)
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId())); ((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
@ -292,7 +300,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
// TODO: refactor // TODO: refactor
private void setupNPCs() { private void setupNPCs() {
saves.load();
int created = 0, spawned = 0; int created = 0, spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name()); int id = Integer.parseInt(key.name());

View File

@ -35,7 +35,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
// set the head yaw in another tick - if done immediately, // set the head yaw in another tick - if done immediately,
// minecraft will not update it. // minecraft will not update it.
} }
}, 1); }, 5);
handle.getBukkitEntity().setSleepingIgnored(true); handle.getBukkitEntity().setSleepingIgnored(true);
return handle; return handle;
} }