Search in sources :

Example 1 with Campfire

use of org.bukkit.block.data.type.Campfire in project Denizen-For-Bukkit by DenizenScript.

the class NPCCommandHandler method sitting.

@Command(aliases = { "npc" }, usage = "sit (--location x,y,z,world) (--anchor anchor_name) (-c)", desc = "Makes the NPC sit.", flags = "c", modifiers = { "sit" }, min = 1, max = 3, permission = "denizen.npc.sit")
@Requirements(selected = true, ownership = true)
public void sitting(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (npc.hasTrait(SneakingTrait.class)) {
        npc.getOrAddTrait(SneakingTrait.class).stand();
        npc.removeTrait(SneakingTrait.class);
    }
    if (npc.hasTrait(SleepingTrait.class)) {
        npc.getOrAddTrait(SleepingTrait.class).wakeUp();
        npc.removeTrait(SleepingTrait.class);
    }
    SittingTrait trait = npc.getOrAddTrait(SittingTrait.class);
    if (args.hasValueFlag("location")) {
        LocationTag location = LocationTag.valueOf(args.getFlag("location"), CoreUtilities.basicContext);
        if (location == null) {
            Messaging.sendError(sender, "Usage: /npc sit --location x,y,z,world");
            return;
        }
        trait.sit(location);
        return;
    } else if (args.hasValueFlag("anchor")) {
        if (npc.hasTrait(Anchors.class)) {
            Anchors anchors = npc.getOrAddTrait(Anchors.class);
            if (anchors.getAnchor(args.getFlag("anchor")) != null) {
                trait.sit(anchors.getAnchor(args.getFlag("anchor")).getLocation());
                Messaging.send(sender, npc.getName() + " is now sitting.");
                return;
            }
        }
        Messaging.sendError(sender, "The NPC does not have the specified anchor!");
        return;
    }
    Location targetLocation;
    if (args.hasFlag('c')) {
        targetLocation = args.getSenderTargetBlockLocation().clone().add(0.5, 0, 0.5);
        targetLocation.setYaw(npc.getStoredLocation().getYaw());
    } else {
        targetLocation = npc.getStoredLocation().clone();
        targetLocation.add(0, -0.2, 0);
    }
    if (trait.isSitting()) {
        Messaging.send(sender, npc.getName() + " is already sitting, use '/npc stand' to stand the NPC back up.");
        return;
    }
    Block block = targetLocation.getBlock();
    BlockData data = block.getBlockData();
    if (data instanceof Stairs || data instanceof Bed || (data instanceof Slab && ((Slab) data).getType() == Slab.Type.BOTTOM)) {
        targetLocation.setY(targetLocation.getBlockY() + 0.3);
    } else if (data instanceof Campfire) {
        targetLocation.setY(targetLocation.getBlockY() + 0.2);
    } else if (block.getType().name().endsWith("CARPET")) {
        targetLocation.setY(targetLocation.getBlockY());
    } else if (block.getType().isSolid()) {
        targetLocation.setY(targetLocation.getBlockY() + 0.8);
    }
    trait.sit(targetLocation);
    Messaging.send(sender, npc.getName() + " is now sitting.");
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Anchors(net.citizensnpcs.trait.Anchors) Bed(org.bukkit.block.data.type.Bed) Campfire(org.bukkit.block.data.type.Campfire) Stairs(org.bukkit.block.data.type.Stairs) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData) Slab(org.bukkit.block.data.type.Slab) Location(org.bukkit.Location) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)1 Command (net.citizensnpcs.api.command.Command)1 Requirements (net.citizensnpcs.api.command.Requirements)1 Anchors (net.citizensnpcs.trait.Anchors)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 BlockData (org.bukkit.block.data.BlockData)1 Bed (org.bukkit.block.data.type.Bed)1 Campfire (org.bukkit.block.data.type.Campfire)1 Slab (org.bukkit.block.data.type.Slab)1 Stairs (org.bukkit.block.data.type.Stairs)1