use of net.aufdemrand.denizencore.exceptions.CommandExecutionException 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;
}
}
Aggregations