diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 1ae9f34e9..429ee823f 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -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)); } /* diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index a43930583..c9d960019 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -615,7 +615,8 @@ public class NPCCommands { for (Trait trait : npc.getTraits()) { if (CitizensAPI.getTraitFactory().isInternalTrait(trait)) continue; - Messaging.send(sender, " - " + trait.getName() + ""); + String message = " - " + 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()); }