From bd6d45184170d0ce1dd4f8ef4f3f44580ea03a60 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 30 Jun 2016 20:13:34 +0200 Subject: [PATCH] Resolve Citizens config spam with clones --- .../dungeonsxl/mob/CitizensMobProvider.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java b/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java index aac46315..fcbe318a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/mob/CitizensMobProvider.java @@ -22,6 +22,8 @@ import java.util.HashSet; import java.util.Set; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.trait.MobType; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; @@ -76,7 +78,7 @@ public class CitizensMobProvider implements ExternalMobProvider { NPC npc = CitizensAPI.getNPCRegistry().getById(NumberUtil.parseInt(mob)); if (npc != null) { - npc = npc.clone(); + npc = createTransientClone(npc); if (npc.isSpawned()) { npc.despawn(); } @@ -89,4 +91,20 @@ public class CitizensMobProvider implements ExternalMobProvider { } } + /** + * Clones an NPC without spamming the config. + * + * @param npc + * the NPC to clone + * @return + * a clone of the NPC + */ + public static NPC createTransientClone(NPC npc) { + NPC copy = CitizensAPI.getNPCRegistry().createNPC(npc.getTrait(MobType.class).getType(), npc.getFullName()); + for (Trait trait : copy.getTraits()) { + trait.onCopy(); + } + return copy; + } + }