mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 20:31:28 +01:00
Resolve Citizens config spam with clones
This commit is contained in:
parent
86341791a0
commit
bd6d451841
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user