From 1f6e5688388466412080180f4c157aeb751fdf07 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 28 Sep 2012 18:03:17 +0800 Subject: [PATCH] Changes to /npc position --- .../command/command/NPCCommands.java | 63 ++++++++----------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 7ff6b271d..660c48158 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -33,7 +33,6 @@ import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Paginator; import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.Util; - import net.minecraft.server.EntityLiving; import org.bukkit.Bukkit; @@ -454,6 +453,33 @@ public class NPCCommands { + " is now the owner of " + StringHelper.wrap(npc.getName()) + "."); } + @Command( + aliases = { "npc" }, + usage = "position (-a)", + desc = "Changes NPC's head position", + flags = "a", + modifiers = { "position" }, + min = 1, + max = 2, + permission = "npc.position.assume") + @Requirements(selected = true, ownership = true) + public void position(CommandContext args, Player player, NPC npc) throws CommandException { + // Assume Player's position + if (args.hasFlag('a')) { + // Spawn the NPC if it isn't spawned to prevent NPEs + if (!npc.isSpawned()) + npc.spawn(npc.getTrait(CurrentLocation.class).getLocation()); + // Update entity with some NMS magic + EntityLiving handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle(); + handle.yaw = player.getLocation().getYaw(); + handle.pitch = player.getLocation().getPitch(); + handle.as = handle.yaw; + return; + } else + Messaging.sendF(player, ChatColor.YELLOW + + "Usage: '/npc position -a' to assume your head position"); + } + @Command( aliases = { "npc" }, usage = "power", @@ -652,39 +678,4 @@ public class NPCCommands { Messaging.sendF(sender, ChatColor.GREEN + "%s is %s vulnerable.", StringHelper.wrap(npc.getName()), vulnerable ? "now" : "no longer"); } - - @Command( - aliases = { "npc" }, - usage = "position (-a)", - desc = "Changes NPC's head position", - flags = "a", - modifiers = { "position" }, - min = 1, - max = 2, - permission = "npc.position.assume") - @Requirements(selected = true, ownership = true, types = { EntityType.PLAYER }) - public void position(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - - // Assume Player's position - if (args.hasFlag('a')) { - if (sender instanceof Player) { - // Spawn the NPC if it isn't spawned to prevent NPEs - if (!npc.isSpawned()) - npc.spawn(npc.getTrait(CurrentLocation.class).getLocation()); - - // Update entity with some NMS magic - EntityLiving handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle(); - handle.yaw = (float) ((Player) sender).getLocation().getYaw(); - handle.pitch = (float) ((Player) sender).getLocation().getPitch(); - handle.as = handle.yaw; - - return; - } - - else - Messaging.sendF(sender, ChatColor.YELLOW + "This command can only be used by a Player in-game"); - } - - Messaging.sendF(sender, ChatColor.YELLOW + "Usage: '/npc position -a' to assume Player's head position"); - } } \ No newline at end of file