Resolve Citizens config spam with clones

This commit is contained in:
Daniel Saukel 2016-06-30 20:13:34 +02:00
parent 86341791a0
commit bd6d451841

View File

@ -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;
}
}