From 350a63f0b82946f33e4eadf837623b41ddd968da Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 3 Jul 2013 18:05:18 +0800 Subject: [PATCH] Validate target NPC in /npc tp --- src/main/java/net/citizensnpcs/commands/NPCCommands.java | 4 ++++ src/main/java/net/citizensnpcs/util/Messages.java | 1 + src/main/resources/messages_en.properties | 1 + 3 files changed, 6 insertions(+) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index ee8d781df..decd1b745 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -1026,6 +1026,10 @@ public class NPCCommands { permission = "citizens.npc.tp") public void tp(CommandContext args, Player player, NPC npc) { Location to = npc.getTrait(CurrentLocation.class).getLocation(); + if (to == null) { + Messaging.sendError(player, Messages.TELEPORT_NPC_LOCATION_NOT_FOUND); + return; + } player.teleport(to, TeleportCause.COMMAND); Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName()); } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index c285220e3..971b77147 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -157,6 +157,7 @@ public class Messages { public static final String SKIPPING_INVALID_POSE = "citizens.notifications.skipping-invalid-pose"; public static final String SPEED_MODIFIER_ABOVE_LIMIT = "citizens.commands.npc.speed.modifier-above-limit"; public static final String SPEED_MODIFIER_SET = "citizens.commands.npc.speed.set"; + public static final String TELEPORT_NPC_LOCATION_NOT_FOUND = "citizens.commands.npc.tp.location-not-found"; public static final String TELEPORTED_TO_NPC = "citizens.commands.npc.tp.teleported"; public static final String TEMPLATE_APPLIED = "citizens.commands.template.applied"; public static final String TEMPLATE_CONFLICT = "citizens.commands.template.conflict"; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 4e1f9a83d..5fa0ea895 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -78,6 +78,7 @@ citizens.commands.npc.spawn.spawned=You spawned [[{0}]]. citizens.commands.npc.speed.modifier-above-limit=Speed is above the limit. citizens.commands.npc.speed.set=NPC speed modifier set to [[{0}]]. citizens.commands.npc.tp.teleported=You teleported to [[{0}]]. +citizens.commands.npc.tp.location-not-found=Couldn't find the target NPC's location. citizens.commands.npc.tpto.success=Teleported successfully. citizens.commands.npc.tpto.to-not-found=Destination entity not found. citizens.commands.npc.tpto.from-not-found=Source entity not found.