Search in sources :

Example 31 with Command

use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.

the class Commands method shulker.

@Command(aliases = { "npc" }, usage = "shulker (--peek [peek] --color [color])", desc = "Sets shulker modifiers.", modifiers = { "shulker" }, min = 1, max = 1, permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
    boolean hasArg = false;
    if (args.hasValueFlag("peek")) {
        int peek = (byte) args.getFlagInteger("peek");
        trait.setPeek(peek);
        Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
        hasArg = true;
    }
    if (args.hasValueFlag("color")) {
        DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
        if (color == null) {
            Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values()));
            return;
        }
        trait.setColor(color);
        Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
        hasArg = true;
    }
    if (!hasArg) {
        throw new CommandUsageException();
    }
}
Also used : CommandUsageException(net.citizensnpcs.api.command.exception.CommandUsageException) DyeColor(org.bukkit.DyeColor) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 32 with Command

use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.

the class Commands method bossbar.

@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    BossBarTrait trait = npc.getTrait(BossBarTrait.class);
    if (args.hasValueFlag("color")) {
        BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
        trait.setColor(color);
    }
    if (args.hasValueFlag("title")) {
        trait.setTitle(args.getFlag("title"));
    }
    if (args.hasValueFlag("visible")) {
        trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
    }
    if (args.hasValueFlag("flags")) {
        List<BarFlag> flags = Lists.newArrayList();
        for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
            BarFlag flag = Util.matchEnum(BarFlag.values(), s);
            if (flag != null) {
                flags.add(flag);
            }
        }
        trait.setFlags(flags);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 33 with Command

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

the class NPCCommandHandler method assignment.

/*
     * ASSIGNMENT
     */
@Command(aliases = { "npc" }, usage = "assignment --set assignment_name (-r)", desc = "Controls the assignment for an NPC.", flags = "r", 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 {
    if (!npc.hasTrait(AssignmentTrait.class)) {
        npc.addTrait(AssignmentTrait.class);
    }
    Player player = null;
    if (sender instanceof Player) {
        player = (Player) sender;
    }
    AssignmentTrait trait = npc.getTrait(AssignmentTrait.class);
    if (args.hasValueFlag("set")) {
        String script = args.getFlag("set").replace("\"", "");
        if (trait.setAssignment(script, dPlayer.mirrorBukkitPlayer(player))) {
            if (trait.hasAssignment()) {
                Messaging.sendInfo(sender, npc.getName() + "'s assignment is now: '" + trait.getAssignment().getName() + "'.");
            } else {
                Messaging.sendInfo(sender, npc.getName() + "'s assignment was not able to be set.");
            }
        } else if (ScriptRegistry.containsScript(script)) {
            Messaging.sendError(sender, "A script with that name exists, but it is not an assignment script!");
        } else {
            Messaging.sendError(sender, "Invalid assignment! Has the script sucessfully loaded, or has it been mispelled?");
        }
        return;
    } else if (args.hasFlag('r')) {
        trait.removeAssignment(dPlayer.mirrorBukkitPlayer(player));
        Messaging.sendInfo(sender, npc.getName() + "'s assignment has been removed.");
        return;
    } else if (args.length() > 2 && args.getInteger(1, 0) < 1) {
        Messaging.send(sender, "");
        Messaging.send(sender, "<f>Use '--set name' to set an assignment script to this NPC.");
        Messaging.send(sender, "<b>Example: /npc assignment --set \"Magic Shop\"");
        Messaging.send(sender, "<f>Remove an assignment with '-r'.");
        Messaging.send(sender, "<f>Note: Assigning a script will fire an 'On Assignment:' action.");
        Messaging.send(sender, "");
        return;
    }
    try {
        trait.describe(sender, args.getInteger(1, 1));
    } catch (net.citizensnpcs.api.command.exception.CommandException e) {
        throw new CommandException(e.getMessage());
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) 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 34 with Command

use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.

the class Commands method bossbar.

@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    BossBarTrait trait = npc.getTrait(BossBarTrait.class);
    if (args.hasValueFlag("color")) {
        BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
        trait.setColor(color);
    }
    if (args.hasValueFlag("title")) {
        trait.setTitle(args.getFlag("title"));
    }
    if (args.hasValueFlag("visible")) {
        trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
    }
    if (args.hasValueFlag("flags")) {
        List<BarFlag> flags = Lists.newArrayList();
        for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
            BarFlag flag = Util.matchEnum(BarFlag.values(), s);
            if (flag != null) {
                flags.add(flag);
            }
        }
        trait.setFlags(flags);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 35 with Command

use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.

the class Commands method llama.

@Command(aliases = { "npc" }, usage = "llama (--color color) (--strength strength)", desc = "Sets llama modifiers", modifiers = { "llama" }, min = 1, max = 1, permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    LlamaTrait trait = npc.getTrait(LlamaTrait.class);
    String output = "";
    if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
        String colorRaw = args.getFlag("color", args.getFlag("colour"));
        Color color = Util.matchEnum(Color.values(), colorRaw);
        if (color == null) {
            String valid = Util.listValuesPretty(Color.values());
            throw new CommandException(Messages.INVALID_LLAMA_COLOR, valid);
        }
        trait.setColor(color);
        output += Messaging.tr(Messages.LLAMA_COLOR_SET, Util.prettyEnum(color));
    }
    if (args.hasValueFlag("strength")) {
        trait.setStrength(Math.max(1, Math.min(5, args.getFlagInteger("strength"))));
        output += Messaging.tr(Messages.LLAMA_STRENGTH_SET, args.getFlagInteger("strength"));
    }
    if (!output.isEmpty()) {
        Messaging.send(sender, output);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) Color(org.bukkit.entity.Llama.Color) DyeColor(org.bukkit.DyeColor) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

Command (net.citizensnpcs.api.command.Command)60 CommandException (net.citizensnpcs.api.command.exception.CommandException)40 Requirements (net.citizensnpcs.api.command.Requirements)39 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)27 Player (org.bukkit.entity.Player)11 Location (org.bukkit.Location)10 NPC (net.citizensnpcs.api.npc.NPC)9 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 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 ArrayList (java.util.ArrayList)2