use of net.citizensnpcs.trait.Poses in project Denizen-For-Bukkit by DenizenScript.
the class PoseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
TargetType target = (TargetType) scriptEntry.getObject("target");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
Action action = (Action) scriptEntry.getObject("action");
ElementTag idElement = scriptEntry.getElement("pose_id");
LocationTag pose_loc = scriptEntry.getObjectTag("pose_loc");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Target", target), (target == TargetType.PLAYER ? Utilities.getEntryPlayer(scriptEntry) : ""), npc, db("Action", action), idElement, pose_loc);
}
if (!npc.getCitizen().hasTrait(Poses.class)) {
npc.getCitizen().addTrait(Poses.class);
}
Poses poses = npc.getCitizen().getOrAddTrait(Poses.class);
String id = idElement.asString();
switch(action) {
case ASSUME:
if (!poses.hasPose(id)) {
Debug.echoError("Pose \"" + id + "\" doesn't exist for " + npc.toString());
}
if (target.name().equals("NPC")) {
poses.assumePose(id);
} else {
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
Location location = player.getLocation();
location.setYaw(poses.getPose(id).getYaw());
location.setPitch(poses.getPose(id).getPitch());
// The only way to change a player's yaw and pitch in Bukkit is to use teleport on them
player.teleport(location);
}
break;
case ADD:
if (!poses.addPose(id, pose_loc)) {
Debug.echoError(npc.toString() + " already has that pose!");
}
break;
case REMOVE:
if (!poses.removePose(id)) {
Debug.echoError(npc.toString() + " does not have that pose!");
}
break;
}
}
use of net.citizensnpcs.trait.Poses in project Denizen-For-Bukkit by DenizenScript.
the class PoseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
TargetType target = (TargetType) scriptEntry.getObject("target");
dNPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
Action action = (Action) scriptEntry.getObject("action");
String id = (String) scriptEntry.getObject("pose_id");
dLocation pose_loc = (dLocation) scriptEntry.getObject("pose_loc");
// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("Target", target.toString()) + (target == TargetType.PLAYER ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().debug() : "") + npc.debug() + aH.debugObj("Action", action.toString()) + aH.debugObj("Id", id) + (pose_loc != null ? pose_loc.debug() : ""));
if (!npc.getCitizen().hasTrait(Poses.class)) {
npc.getCitizen().addTrait(Poses.class);
}
Poses poses = npc.getCitizen().getTrait(Poses.class);
switch(action) {
case ASSUME:
if (!poses.hasPose(id)) {
throw new CommandExecutionException("Pose \"" + id + "\" doesn't exist for " + npc.toString());
}
if (target.name().equals("NPC")) {
poses.assumePose(id);
} else {
Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
Location location = player.getLocation();
location.setYaw(poses.getPose(id).getYaw());
location.setPitch(poses.getPose(id).getPitch());
// The only way to change a player's yaw and pitch in Bukkit
// is to use teleport on him/her
player.teleport(location);
}
break;
case ADD:
if (!poses.addPose(id, pose_loc)) {
throw new CommandExecutionException(npc.toString() + " already has that pose!");
}
break;
case REMOVE:
if (!poses.removePose(id)) {
throw new CommandExecutionException(npc.toString() + " does not have that pose!");
}
break;
}
}
use of net.citizensnpcs.trait.Poses in project Citizens2 by CitizensDev.
the class NPCCommands method pose.
@Command(aliases = { "npc" }, usage = "pose (--save [name]|--assume [name]|--remove [name]) (-a)", desc = "Changes/Saves/Lists NPC's head pose(s)", flags = "a", modifiers = { "pose" }, min = 1, max = 2, permission = "citizens.npc.pose")
public void pose(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Poses trait = npc.getTrait(Poses.class);
if (args.hasValueFlag("save")) {
if (args.getFlag("save").isEmpty())
throw new CommandException(Messages.INVALID_POSE_NAME);
if (args.getSenderLocation() == null)
throw new ServerCommandException();
if (trait.addPose(args.getFlag("save"), args.getSenderLocation())) {
Messaging.sendTr(sender, Messages.POSE_ADDED);
} else
throw new CommandException(Messages.POSE_ALREADY_EXISTS, args.getFlag("save"));
} else if (args.hasValueFlag("assume")) {
String pose = args.getFlag("assume");
if (pose.isEmpty())
throw new CommandException(Messages.INVALID_POSE_NAME);
if (!trait.hasPose(pose))
throw new CommandException(Messages.POSE_MISSING, pose);
trait.assumePose(pose);
} else if (args.hasValueFlag("remove")) {
if (args.getFlag("remove").isEmpty())
throw new CommandException(Messages.INVALID_POSE_NAME);
if (trait.removePose(args.getFlag("remove"))) {
Messaging.sendTr(sender, Messages.POSE_REMOVED);
} else
throw new CommandException(Messages.POSE_MISSING, args.getFlag("remove"));
} else if (!args.hasFlag('a')) {
trait.describe(sender, args.getInteger(1, 1));
}
// Assume Player's pose
if (!args.hasFlag('a'))
return;
if (args.getSenderLocation() == null)
throw new ServerCommandException();
Location location = args.getSenderLocation();
trait.assumePose(location);
}
Aggregations