mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-02 14:38:19 +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.NPCDamageByBlockEvent;
|
||||||
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
|
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
|
||||||
import net.citizensnpcs.api.event.NPCDamageEvent;
|
import net.citizensnpcs.api.event.NPCDamageEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCDeathEvent;
|
||||||
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
||||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||||
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
||||||
@ -163,6 +164,7 @@ public class EventListen implements Listener {
|
|||||||
if (!npcRegistry.isNPC(event.getEntity()))
|
if (!npcRegistry.isNPC(event.getEntity()))
|
||||||
return;
|
return;
|
||||||
NPC npc = npcRegistry.getNPC(event.getEntity());
|
NPC npc = npcRegistry.getNPC(event.getEntity());
|
||||||
|
Bukkit.getPluginManager().callEvent(new NPCDeathEvent(npc, event));
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,12 +176,12 @@ public class EventListen implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityTarget(EntityTargetEvent event) {
|
public void onEntityTarget(EntityTargetEvent event) {
|
||||||
if (npcRegistry.isNPC(event.getTarget())) {
|
if (!npcRegistry.isNPC(event.getTarget()))
|
||||||
NPC npc = npcRegistry.getNPC(event.getTarget());
|
return;
|
||||||
|
NPC npc = npcRegistry.getNPC(event.getTarget());
|
||||||
|
|
||||||
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
|
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
|
||||||
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
|
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -615,7 +615,8 @@ public class NPCCommands {
|
|||||||
for (Trait trait : npc.getTraits()) {
|
for (Trait trait : npc.getTraits()) {
|
||||||
if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
|
if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
|
||||||
continue;
|
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,
|
max = 1,
|
||||||
permission = "npc.tp")
|
permission = "npc.tp")
|
||||||
public void tp(CommandContext args, Player player, NPC npc) {
|
public void tp(CommandContext args, Player player, NPC npc) {
|
||||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
Location to = npc.getTrait(CurrentLocation.class).getLocation();
|
||||||
if (!npc.isSpawned())
|
player.teleport(to, TeleportCause.COMMAND);
|
||||||
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
|
||||||
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
|
||||||
Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName());
|
Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user