mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-30 13:09:10 +01:00
Fix issue with /npc tp, implement NPCDeathEvent
This commit is contained in:
parent
0d56317bc0
commit
32f91d39cd
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user