Search in sources :

Example 1 with Poses

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;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Player(org.bukkit.entity.Player) NPCTag(com.denizenscript.denizen.objects.NPCTag) Poses(net.citizensnpcs.trait.Poses) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Location(org.bukkit.Location)

Example 2 with Poses

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

Example 3 with Poses

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);
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) Poses(net.citizensnpcs.trait.Poses) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command)

Aggregations

Poses (net.citizensnpcs.trait.Poses)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)2 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)1 Command (net.citizensnpcs.api.command.Command)1 CommandException (net.citizensnpcs.api.command.exception.CommandException)1 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)1 CurrentLocation (net.citizensnpcs.trait.CurrentLocation)1