Call onRemove

This commit is contained in:
fullwall 2012-10-08 12:37:45 +08:00
parent 091ce13cca
commit d442da91fb
4 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.scripting.EventRegistrar; import net.citizensnpcs.api.scripting.EventRegistrar;
import net.citizensnpcs.api.scripting.ObjectProvider; import net.citizensnpcs.api.scripting.ObjectProvider;
import net.citizensnpcs.api.scripting.ScriptCompiler; import net.citizensnpcs.api.scripting.ScriptCompiler;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitFactory; import net.citizensnpcs.api.trait.TraitFactory;
import net.citizensnpcs.command.CommandContext; import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.CommandManager; import net.citizensnpcs.command.CommandManager;
@ -73,6 +74,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
while (itr.hasNext()) { while (itr.hasNext()) {
NPC npc = itr.next(); NPC npc = itr.next();
npc.despawn(); npc.despawn();
for (Trait t : npc.getTraits())
t.onRemove();
itr.remove(); itr.remove();
} }
} }

View File

@ -705,7 +705,7 @@ public class NPCCommands {
if (!npc.isSpawned()) if (!npc.isSpawned())
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation()); npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND); player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC); Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName());
} }
@Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport a NPC to your location", modifiers = { @Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport a NPC to your location", modifiers = {

View File

@ -89,7 +89,7 @@ public abstract class CitizensNPC extends AbstractNPC {
if (hasTrait(clazz)) { if (hasTrait(clazz)) {
trait = getTrait(clazz); trait = getTrait(clazz);
} else { } else {
trait = CitizensAPI.getTraitFactory().getTrait(traitKey.name()); trait = CitizensAPI.getTraitFactory().getTrait(clazz);
if (trait == null) { if (trait == null) {
Messaging.severeTr(Messages.SKIPPING_BROKEN_TRAIT, traitKey.name(), getId()); Messaging.severeTr(Messages.SKIPPING_BROKEN_TRAIT, traitKey.name(), getId());
continue; continue;

View File

@ -7,6 +7,7 @@ import java.util.Map;
import net.citizensnpcs.NPCDataStore; import net.citizensnpcs.NPCDataStore;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.entity.CitizensBlazeNPC; import net.citizensnpcs.npc.entity.CitizensBlazeNPC;
import net.citizensnpcs.npc.entity.CitizensCaveSpiderNPC; import net.citizensnpcs.npc.entity.CitizensCaveSpiderNPC;
@ -104,6 +105,8 @@ public class CitizensNPCRegistry implements NPCRegistry {
NPC npc = itr.next(); NPC npc = itr.next();
itr.remove(); itr.remove();
npc.despawn(); npc.despawn();
for (Trait t : npc.getTraits())
t.onRemove();
saves.remove(npc); saves.remove(npc);
} }
} }