Search in sources :

Example 21 with CommandExecutionException

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;
    }
}
Also used : Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Poses(net.citizensnpcs.trait.Poses) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)21 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)17 Element (net.aufdemrand.denizencore.objects.Element)16 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)8 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)8 Duration (net.aufdemrand.denizencore.objects.Duration)6 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)5 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)5 List (java.util.List)4 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)4 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)4 Player (org.bukkit.entity.Player)4 File (java.io.File)3 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)3 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)3 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)3 ScriptQueue (net.aufdemrand.denizencore.scripts.queues.ScriptQueue)3 Location (org.bukkit.Location)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 Vector (org.bukkit.util.Vector)2