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

View File

@ -705,7 +705,7 @@ public class NPCCommands {
if (!npc.isSpawned())
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
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 = {

View File

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

View File

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