Fix issue with /npc tp, implement NPCDeathEvent

This commit is contained in:
fullwall 2012-11-17 12:54:58 +08:00
parent 0cc761e989
commit 2eac790093
2 changed files with 11 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import net.citizensnpcs.api.event.NPCCombustEvent;
import net.citizensnpcs.api.event.NPCDamageByBlockEvent;
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
import net.citizensnpcs.api.event.NPCDamageEvent;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
@ -163,6 +164,7 @@ public class EventListen implements Listener {
if (!npcRegistry.isNPC(event.getEntity()))
return;
NPC npc = npcRegistry.getNPC(event.getEntity());
Bukkit.getPluginManager().callEvent(new NPCDeathEvent(npc, event));
npc.despawn();
}
@ -174,12 +176,12 @@ public class EventListen implements Listener {
@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
if (npcRegistry.isNPC(event.getTarget())) {
NPC npc = npcRegistry.getNPC(event.getTarget());
if (!npcRegistry.isNPC(event.getTarget()))
return;
NPC npc = npcRegistry.getNPC(event.getTarget());
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
}
/*

View File

@ -615,7 +615,8 @@ public class NPCCommands {
for (Trait trait : npc.getTraits()) {
if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
continue;
Messaging.send(sender, " <e>- <a>" + trait.getName() + "<e>");
String message = " <e>- <a>" + trait.getName();
Messaging.send(sender, message);
}
}
@ -961,10 +962,8 @@ public class NPCCommands {
max = 1,
permission = "npc.tp")
public void tp(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned())
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
Location to = npc.getTrait(CurrentLocation.class).getLocation();
player.teleport(to, TeleportCause.COMMAND);
Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName());
}