mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-10-02 09:08:02 +02:00
fix teleporting NPE
This commit is contained in:
parent
310e81b338
commit
c89724b391
@ -8,6 +8,7 @@ import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory;
|
|||||||
import net.citizensnpcs.api.npc.trait.SaveId;
|
import net.citizensnpcs.api.npc.trait.SaveId;
|
||||||
import net.citizensnpcs.api.npc.trait.trait.MobType;
|
import net.citizensnpcs.api.npc.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.npc.trait.trait.Owner;
|
import net.citizensnpcs.api.npc.trait.trait.Owner;
|
||||||
|
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
|
||||||
import net.citizensnpcs.api.npc.trait.trait.Spawned;
|
import net.citizensnpcs.api.npc.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.command.CommandContext;
|
import net.citizensnpcs.command.CommandContext;
|
||||||
import net.citizensnpcs.command.annotation.Command;
|
import net.citizensnpcs.command.annotation.Command;
|
||||||
@ -242,6 +243,9 @@ public class NPCCommands {
|
|||||||
max = 1,
|
max = 1,
|
||||||
permission = "npc.tphere")
|
permission = "npc.tphere")
|
||||||
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
|
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
|
||||||
|
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||||
|
if (!npc.isSpawned())
|
||||||
|
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
||||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
||||||
}
|
}
|
||||||
@ -255,6 +259,9 @@ public class NPCCommands {
|
|||||||
max = 1,
|
max = 1,
|
||||||
permission = "npc.tp")
|
permission = "npc.tp")
|
||||||
public void teleportToNPC(CommandContext args, Player player, NPC npc) {
|
public void teleportToNPC(CommandContext args, Player player, NPC npc) {
|
||||||
|
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||||
|
if (!npc.isSpawned())
|
||||||
|
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
||||||
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
||||||
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user