Changes to /npc position

This commit is contained in:
fullwall 2012-09-28 18:03:17 +08:00
parent da723d47e8
commit 5d80957236

View File

@ -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");
}
}