From cef9169b549ca1df8a715dd31979d9fa43760728 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 17 Nov 2017 15:03:50 +0100 Subject: [PATCH] Fix Citizens NPC saving; resolves #166; resolves #235 --- .../io/github/dre2n/dungeonsxl/mob/DNPCRegistry.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/mob/DNPCRegistry.java b/src/main/java/io/github/dre2n/dungeonsxl/mob/DNPCRegistry.java index 284e1c4c..c6815071 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/mob/DNPCRegistry.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/mob/DNPCRegistry.java @@ -20,16 +20,20 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Iterator; import java.util.UUID; +import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.event.NPCCreateEvent; import net.citizensnpcs.api.npc.AbstractNPC; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPCRegistry; +import net.citizensnpcs.api.persistence.PersistenceLoader; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.MemoryDataKey; import net.citizensnpcs.trait.ArmorStandTrait; +import net.citizensnpcs.trait.LookClose; +import net.citizensnpcs.trait.MountTrait; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -67,6 +71,10 @@ public class DNPCRegistry implements NPCRegistry { if (type == EntityType.ARMOR_STAND && !npc.hasTrait(ArmorStandTrait.class)) { npc.addTrait(ArmorStandTrait.class); } + if (Setting.DEFAULT_LOOK_CLOSE.asBoolean()) { + npc.addTrait(LookClose.class); + } + npc.addTrait(MountTrait.class); return npc; } @@ -148,6 +156,8 @@ public class DNPCRegistry implements NPCRegistry { for (Trait trait : npc.getTraits()) { DataKey traitKey = root.getRelative("traits." + trait.getName()); trait.save(traitKey); + PersistenceLoader.save(trait, traitKey); + //npc.removedTraits.remove(trait.getName()); traitNames.append(trait.getName() + ","); } if (traitNames.length() > 0) { @@ -155,6 +165,7 @@ public class DNPCRegistry implements NPCRegistry { } else { root.setString("traitnames", ""); } + //npc.removedTraits.clear(); } }