Search in sources :

Example 61 with Command

use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.

the class NPCCommandHandler method trigger.

@Command(aliases = { "npc" }, usage = "trigger [trigger name] [(--cooldown [seconds])|(--radius [radius])|(-t)]", desc = "Controls the various triggers for an NPC.", flags = "t", modifiers = { "trigger", "tr" }, min = 1, max = 3, permission = "denizen.npc.trigger")
@Requirements(selected = true, ownership = true)
public void trigger(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    TriggerTrait trait = npc.getOrAddTrait(TriggerTrait.class);
    if ((args.hasValueFlag("name") || (args.argsLength() > 1 && (args.getJoinedStrings(1) != null) && !args.getString(1).matches("\\d+")))) {
        // Get the name of the trigger
        String triggerName;
        if (args.hasValueFlag("name")) {
            triggerName = args.getFlag("name");
        } else {
            triggerName = args.getJoinedStrings(1);
        }
        // Check to make sure trigger exists
        if (Denizen.getInstance().triggerRegistry.get(triggerName) == null) {
            Messaging.sendError(sender, "'" + triggerName.toUpperCase() + "' trigger does not exist.");
            Messaging.send(sender, "<f>Usage: /npc trigger [trigger_name] [(--cooldown #)|(--radius #)|(-t)]");
            Messaging.send(sender, "");
            Messaging.send(sender, "<f>Use '--name trigger_name' to specify a specific trigger, and '-t' to toggle.");
            Messaging.send(sender, "<b>Example: /npc trigger --name damage -t");
            Messaging.send(sender, "<f>You may also use '--cooldown #' to specify a new cooldown time, and '--radius #' to specify a specific radius, when applicable.");
            Messaging.send(sender, "");
            return;
        }
        // If toggling
        if (args.hasFlag('t')) {
            trait.toggleTrigger(triggerName);
        }
        // If setting cooldown
        if (args.hasValueFlag("cooldown")) {
            trait.setLocalCooldown(triggerName, args.getFlagDouble("cooldown"));
        }
        // If specifying radius
        if (args.hasValueFlag("radius")) {
            trait.setLocalRadius(triggerName, args.getFlagInteger("radius"));
            Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger radius now " + args.getFlag("radius") + ".");
        }
        // Show current status of the trigger
        Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger " + (trait.isEnabled(triggerName) ? "is" : "is not") + " currently enabled" + (trait.isEnabled(triggerName) ? " with a cooldown of '" + trait.getCooldownDuration(triggerName) + "' seconds." : "."));
        return;
    }
    try {
        trait.describe(sender, args.getInteger(1, 1));
    } catch (net.citizensnpcs.api.command.exception.CommandException e) {
        throw new CommandException(e.getMessage());
    }
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 62 with Command

use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.

the class NPCCommandHandler method sleeping.

@Command(aliases = { "npc" }, usage = "sleep (--location x,y,z,world) (--anchor anchor_name)", desc = "Makes the NPC sleep.", modifiers = { "sleep" }, min = 1, max = 3, permission = "denizen.npc.sleep")
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER, EntityType.PLAYER })
public void sleeping(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(SittingTrait.class)) {
        npc.getOrAddTrait(SittingTrait.class).stand();
        npc.removeTrait(SittingTrait.class);
    }
    SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class);
    if (trait.isSleeping()) {
        Messaging.send(sender, npc.getName() + " was already sleeping, and is now standing!");
        trait.wakeUp();
        npc.removeTrait(SleepingTrait.class);
        return;
    }
    if (args.hasValueFlag("location")) {
        LocationTag location = LocationTag.valueOf(args.getFlag("location"), CoreUtilities.basicContext);
        if (location == null) {
            Messaging.sendError(sender, "Usage: /npc sleep --location x,y,z,world");
            return;
        }
        trait.toSleep(location);
    } else if (args.hasValueFlag("anchor")) {
        if (npc.hasTrait(Anchors.class)) {
            Anchors anchors = npc.getOrAddTrait(Anchors.class);
            if (anchors.getAnchor(args.getFlag("anchor")) != null) {
                trait.toSleep(anchors.getAnchor(args.getFlag("anchor")).getLocation());
                Messaging.send(sender, npc.getName() + " is now sleeping.");
                return;
            }
        }
        Messaging.sendError(sender, "The NPC does not have the specified anchor!");
        return;
    } else {
        trait.toSleep();
    }
    if (!trait.isSleeping()) {
        npc.removeTrait(SleepingTrait.class);
    }
    Messaging.send(sender, npc.getName() + " is now sleeping.");
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Anchors(net.citizensnpcs.trait.Anchors) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 63 with Command

use of net.citizensnpcs.api.command.Command 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)

Example 64 with Command

use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.

the class NPCCommandHandler method startFishing.

@Command(aliases = { "npc" }, usage = "fish (--location x,y,z,world) (--anchor anchor_name) (-c) (--reel_time <duration>) (--cast_time <duration>)", desc = "Makes the NPC fish, casting at the given location.", flags = "c", modifiers = { "fish" }, min = 1, max = 3, permission = "denizen.npc.fish")
@Requirements(selected = true, ownership = true)
public void startFishing(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    FishingTrait trait = npc.getOrAddTrait(FishingTrait.class);
    if (trait.isFishing()) {
        Messaging.sendError(sender, npc.getName() + " is already fishing! Use '/npc stopfishing' to stop.");
        return;
    }
    if (args.hasValueFlag("percent")) {
        trait.setCatchPercent(args.getFlagInteger("percent"));
    }
    if (args.hasValueFlag("reel_time")) {
        DurationTag duration = DurationTag.valueOf(args.getFlag("reel_time"), CoreUtilities.basicContext);
        if (duration == null) {
            Messaging.sendError(sender, "Invalid reel duration.");
            return;
        }
        trait.reelTickRate = duration.getTicksAsInt();
        Messaging.send(sender, "Set reel rate to " + duration.formatted(true));
    }
    if (args.hasValueFlag("cast_time")) {
        DurationTag duration = DurationTag.valueOf(args.getFlag("cast_time"), CoreUtilities.basicContext);
        if (duration == null) {
            Messaging.sendError(sender, "Invalid cast duration.");
            return;
        }
        trait.reelTickRate = duration.getTicksAsInt();
        Messaging.send(sender, "Set cast rate to " + duration.formatted(true));
    }
    if (args.hasFlag('c')) {
        trait.startFishing(args.getSenderTargetBlockLocation());
    } else if (args.hasValueFlag("location")) {
        String[] argsArray = args.getFlag("location").split(",");
        if (argsArray.length != 4) {
            Messaging.sendError(sender, "Usage: /npc fish --location x,y,z,world");
            return;
        }
        trait.startFishing(LocationTag.valueOf(argsArray[0] + "," + argsArray[1] + "," + argsArray[2] + "," + argsArray[3], CoreUtilities.basicContext));
    } else if (args.hasValueFlag("anchor")) {
        if (npc.hasTrait(Anchors.class)) {
            Anchors anchors = npc.getOrAddTrait(Anchors.class);
            if (anchors.getAnchor(args.getFlag("anchor")) != null) {
                trait.startFishing(anchors.getAnchor(args.getFlag("anchor")).getLocation());
            }
        }
        Messaging.sendError(sender, "The NPC does not have the specified anchor!");
    } else {
        trait.startFishing();
    }
    Messaging.send(sender, npc.getName() + " is now fishing.");
}
Also used : Anchors(net.citizensnpcs.trait.Anchors) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 65 with Command

use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.

the class NPCCommandHandler method assignment.

@Command(aliases = { "npc" }, usage = "assignment ((--set|--remove|--add) assignment_name) (-c)", desc = "Controls the assignment for an NPC.", flags = "rc", modifiers = { "assignment", "assign" }, min = 1, max = 3, permission = "denizen.npc.assign")
@Requirements(selected = true, ownership = true)
public void assignment(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Player player = null;
    if (sender instanceof Player) {
        player = (Player) sender;
    }
    if (args.hasFlag('r') || args.hasFlag('c')) {
        if (!npc.hasTrait(AssignmentTrait.class)) {
            Messaging.sendError(sender, "That NPC has no assignments.");
            return;
        }
        npc.getOrAddTrait(AssignmentTrait.class).clearAssignments(PlayerTag.mirrorBukkitPlayer(player));
        npc.removeTrait(AssignmentTrait.class);
        Messaging.sendInfo(sender, npc.getName() + "<f>'s assignments have been cleared.");
        return;
    }
    if (args.hasValueFlag("set")) {
        String script = args.getFlag("set").replace("\"", "");
        ScriptContainer container = ScriptRegistry.getScriptContainer(script);
        if (container == null) {
            Messaging.sendError(sender, "Invalid assignment! Has the script successfully loaded, or has it been misspelled?");
        } else if (!(container instanceof AssignmentScriptContainer)) {
            Messaging.sendError(sender, "A script with that name exists, but it is not an assignment script!");
        } else {
            AssignmentTrait trait = npc.getOrAddTrait(AssignmentTrait.class);
            trait.clearAssignments(PlayerTag.mirrorBukkitPlayer(player));
            trait.addAssignmentScript((AssignmentScriptContainer) container, PlayerTag.mirrorBukkitPlayer(player));
            Messaging.sendInfo(sender, npc.getName() + "<f>'s assignment is now just: '" + container.getName() + "'.");
        }
        return;
    } else if (args.hasValueFlag("add")) {
        String script = args.getFlag("add").replace("\"", "");
        ScriptContainer container = ScriptRegistry.getScriptContainer(script);
        AssignmentTrait trait = npc.getOrAddTrait(AssignmentTrait.class);
        if (container == null) {
            Messaging.sendError(sender, "Invalid assignment! Has the script successfully loaded, or has it been misspelled?");
        } else if (!(container instanceof AssignmentScriptContainer)) {
            Messaging.sendError(sender, "A script with that name exists, but it is not an assignment script!");
        } else if (trait.addAssignmentScript((AssignmentScriptContainer) container, PlayerTag.mirrorBukkitPlayer(player))) {
            Messaging.sendInfo(sender, npc.getName() + "<f> is now assigned to '" + container.getName() + "'.");
        } else {
            Messaging.sendError(sender, "That NPC was already assigned that script.");
        }
        return;
    } else if (args.hasValueFlag("remove")) {
        String script = args.getFlag("remove").replace("\"", "");
        AssignmentTrait trait = npc.getOrAddTrait(AssignmentTrait.class);
        if (trait.removeAssignmentScript(script, PlayerTag.mirrorBukkitPlayer(player))) {
            trait.checkAutoRemove();
            if (npc.hasTrait(AssignmentTrait.class)) {
                Messaging.sendInfo(sender, npc.getName() + "<f> is no longer assigned to '" + script + "'.");
            } else {
                Messaging.sendInfo(sender, npc.getName() + "<f> no longer has any assignment.");
            }
        } else {
            Messaging.sendError(sender, "That NPC was already not assigned that script.");
        }
        return;
    }
    Messaging.send(sender, "");
    Messaging.send(sender, "<f>Use '--set name' to set a single assignment script to this NPC.");
    Messaging.send(sender, "<b>Example: /npc assignment --set \"Magic Shop\"");
    Messaging.send(sender, "<f>Use '--add name' to add an assignment, or '--remove name' to remove one assignment.");
    Messaging.send(sender, "<f>Clear all assignments with '-c'.");
    Messaging.send(sender, "<f>Note: Assigning a script will fire an 'On Assignment:' action.");
    Messaging.send(sender, "");
}
Also used : AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) ScriptContainer(com.denizenscript.denizencore.scripts.containers.ScriptContainer) Player(org.bukkit.entity.Player) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

Command (net.citizensnpcs.api.command.Command)66 Requirements (net.citizensnpcs.api.command.Requirements)45 CommandException (net.citizensnpcs.api.command.exception.CommandException)40 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)27 Location (org.bukkit.Location)13 Player (org.bukkit.entity.Player)13 NPC (net.citizensnpcs.api.npc.NPC)10 CurrentLocation (net.citizensnpcs.trait.CurrentLocation)9 DyeColor (org.bukkit.DyeColor)8 BarColor (org.bukkit.boss.BarColor)5 NoPermissionsException (net.citizensnpcs.api.command.exception.NoPermissionsException)4 Owner (net.citizensnpcs.api.trait.trait.Owner)4 Anchors (net.citizensnpcs.trait.Anchors)4 CommandUsageException (net.citizensnpcs.api.command.exception.CommandUsageException)3 MobType (net.citizensnpcs.api.trait.trait.MobType)3 Paginator (net.citizensnpcs.api.util.Paginator)3 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)3 ScriptTrait (net.citizensnpcs.trait.ScriptTrait)3 SheepTrait (net.citizensnpcs.trait.SheepTrait)3 LocationTag (com.denizenscript.denizen.objects.LocationTag)2