Search in sources :

Example 6 with CommandException

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

the class Poses method describe.

public void describe(CommandSender sender, int page) throws CommandException {
    Paginator paginator = new Paginator().header("Pose");
    paginator.addLine("<e>Key: <a>ID  <b>Name  <c>Pitch/Yaw");
    int i = 0;
    for (Pose pose : poses.values()) {
        String line = "<a>" + i + "<b>  " + pose.getName() + "<c>  " + pose.getPitch() + "/" + pose.getYaw();
        paginator.addLine(line);
        i++;
    }
    if (!paginator.sendPage(sender, page))
        throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
Also used : Pose(net.citizensnpcs.util.Pose) CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator)

Example 7 with CommandException

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

the class Commands method parrot.

@Command(aliases = { "npc" }, usage = "parrot (--variant variant)", desc = "Sets parrot modifiers", modifiers = { "parrot" }, min = 1, max = 1, permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    ParrotTrait trait = npc.getTrait(ParrotTrait.class);
    String output = "";
    if (args.hasValueFlag("variant")) {
        String variantRaw = args.getFlag("variant");
        Variant variant = Util.matchEnum(Variant.values(), variantRaw);
        if (variant == null) {
            String valid = Util.listValuesPretty(Variant.values());
            throw new CommandException(Messages.INVALID_PARROT_VARIANT, valid);
        }
        trait.setVariant(variant);
        output += Messaging.tr(Messages.PARROT_VARIANT_SET, Util.prettyEnum(variant));
    }
    if (!output.isEmpty()) {
        Messaging.send(sender, output);
    }
}
Also used : Variant(org.bukkit.entity.Parrot.Variant) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 8 with CommandException

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

the class NPCCommands method minecart.

@Command(aliases = { "npc" }, usage = "minecart (--item item_name(:data)) (--offset offset)", desc = "Sets minecart item", modifiers = { "minecart" }, min = 1, max = 1, flags = "", permission = "citizens.npc.minecart")
@Requirements(selected = true, ownership = true, types = { EntityType.MINECART, EntityType.MINECART_CHEST, EntityType.MINECART_COMMAND, EntityType.MINECART_FURNACE, EntityType.MINECART_HOPPER, EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT })
public void minecart(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (args.hasValueFlag("item")) {
        String raw = args.getFlag("item");
        int data = 0;
        if (raw.contains(":")) {
            int dataIndex = raw.indexOf(':');
            data = Integer.parseInt(raw.substring(dataIndex + 1));
            raw = raw.substring(0, dataIndex);
        }
        Material material = Material.matchMaterial(raw);
        if (material == null)
            throw new CommandException();
        npc.data().setPersistent(NPC.MINECART_ITEM_METADATA, material.name());
        npc.data().setPersistent(NPC.MINECART_ITEM_DATA_METADATA, data);
    }
    if (args.hasValueFlag("offset")) {
        npc.data().setPersistent(NPC.MINECART_OFFSET_METADATA, args.getFlagInteger("offset"));
    }
    Messaging.sendTr(sender, Messages.MINECART_SET, npc.data().get(NPC.MINECART_ITEM_METADATA, ""), npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0), npc.data().get(NPC.MINECART_OFFSET_METADATA, 0));
}
Also used : Material(org.bukkit.Material) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 9 with CommandException

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

the class NPCCommands method glowing.

@Command(aliases = { "npc" }, usage = "glowing --color [minecraft chat color]", desc = "Toggles an NPC's glowing status", modifiers = { "glowing" }, min = 1, max = 1, permission = "citizens.npc.glowing")
@Requirements(selected = true, ownership = true)
public void glowing(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (args.hasValueFlag("color")) {
        ChatColor chatColor = Util.matchEnum(ChatColor.values(), args.getFlag("color"));
        if (!(npc.getEntity() instanceof Player))
            throw new CommandException();
        if (chatColor == null) {
            npc.data().remove(NPC.GLOWING_COLOR_METADATA);
        } else {
            npc.data().setPersistent(NPC.GLOWING_COLOR_METADATA, chatColor.name());
        }
        Messaging.sendTr(sender, Messages.GLOWING_COLOR_SET, npc.getName(), chatColor == null ? ChatColor.WHITE + "white" : chatColor + Util.prettyEnum(chatColor));
        return;
    }
    npc.data().setPersistent(NPC.GLOWING_METADATA, !npc.data().get(NPC.GLOWING_METADATA, false));
    boolean glowing = npc.data().get(NPC.GLOWING_METADATA);
    Messaging.sendTr(sender, glowing ? Messages.GLOWING_SET : Messages.GLOWING_UNSET, npc.getName());
}
Also used : Player(org.bukkit.entity.Player) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) ChatColor(org.bukkit.ChatColor) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 10 with CommandException

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

the class NPCCommands method anchor.

@Command(aliases = { "npc" }, usage = "anchor (--save [name]|--assume [name]|--remove [name]) (-a)(-c)", desc = "Changes/Saves/Lists NPC's location anchor(s)", flags = "ac", modifiers = { "anchor" }, min = 1, max = 3, permission = "citizens.npc.anchor")
public void anchor(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Anchors trait = npc.getTrait(Anchors.class);
    if (args.hasValueFlag("save")) {
        if (args.getFlag("save").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        if (args.getSenderLocation() == null)
            throw new ServerCommandException();
        if (args.hasFlag('c')) {
            if (trait.addAnchor(args.getFlag("save"), args.getSenderTargetBlockLocation())) {
                Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
            } else
                throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
        } else {
            if (trait.addAnchor(args.getFlag("save"), args.getSenderLocation())) {
                Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
            } else
                throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
        }
    } else if (args.hasValueFlag("assume")) {
        if (args.getFlag("assume").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        Anchor anchor = trait.getAnchor(args.getFlag("assume"));
        if (anchor == null)
            throw new CommandException(Messages.ANCHOR_MISSING, args.getFlag("assume"));
        npc.teleport(anchor.getLocation(), TeleportCause.COMMAND);
    } else if (args.hasValueFlag("remove")) {
        if (args.getFlag("remove").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        if (trait.removeAnchor(trait.getAnchor(args.getFlag("remove"))))
            Messaging.sendTr(sender, Messages.ANCHOR_REMOVED);
        else
            throw new CommandException(Messages.ANCHOR_MISSING, args.getFlag("remove"));
    } else if (!args.hasFlag('a')) {
        Paginator paginator = new Paginator().header("Anchors");
        paginator.addLine("<e>Key: <a>ID  <b>Name  <c>World  <d>Location (X,Y,Z)");
        for (int i = 0; i < trait.getAnchors().size(); i++) {
            if (trait.getAnchors().get(i).isLoaded()) {
                String line = "<a>" + i + "<b>  " + trait.getAnchors().get(i).getName() + "<c>  " + trait.getAnchors().get(i).getLocation().getWorld().getName() + "<d>  " + trait.getAnchors().get(i).getLocation().getBlockX() + ", " + trait.getAnchors().get(i).getLocation().getBlockY() + ", " + trait.getAnchors().get(i).getLocation().getBlockZ();
                paginator.addLine(line);
            } else {
                String[] parts = trait.getAnchors().get(i).getUnloadedValue();
                String line = "<a>" + i + "<b>  " + trait.getAnchors().get(i).getName() + "<c>  " + parts[0] + "<d>  " + parts[1] + ", " + parts[2] + ", " + parts[3] + " <f>(unloaded)";
                paginator.addLine(line);
            }
        }
        int page = args.getInteger(1, 1);
        if (!paginator.sendPage(sender, page))
            throw new CommandException(Messages.COMMAND_PAGE_MISSING);
    }
    // Assume Player's position
    if (!args.hasFlag('a'))
        return;
    if (sender instanceof ConsoleCommandSender)
        throw new ServerCommandException();
    npc.teleport(args.getSenderLocation(), TeleportCause.COMMAND);
}
Also used : Anchors(net.citizensnpcs.trait.Anchors) Anchor(net.citizensnpcs.util.Anchor) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Paginator(net.citizensnpcs.api.util.Paginator) Command(net.citizensnpcs.api.command.Command)

Aggregations

CommandException (net.citizensnpcs.api.command.exception.CommandException)49 Command (net.citizensnpcs.api.command.Command)40 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)30 Requirements (net.citizensnpcs.api.command.Requirements)25 NPC (net.citizensnpcs.api.npc.NPC)9 Player (org.bukkit.entity.Player)8 Paginator (net.citizensnpcs.api.util.Paginator)7 Location (org.bukkit.Location)7 CurrentLocation (net.citizensnpcs.trait.CurrentLocation)6 DyeColor (org.bukkit.DyeColor)5 NoPermissionsException (net.citizensnpcs.api.command.exception.NoPermissionsException)4 Owner (net.citizensnpcs.api.trait.trait.Owner)4 UnhandledCommandException (net.citizensnpcs.api.command.exception.UnhandledCommandException)3 WrappedCommandException (net.citizensnpcs.api.command.exception.WrappedCommandException)3 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)3 CommandUsageException (net.citizensnpcs.api.command.exception.CommandUsageException)2 CommandSenderCreateNPCEvent (net.citizensnpcs.api.event.CommandSenderCreateNPCEvent)2 PlayerCreateNPCEvent (net.citizensnpcs.api.event.PlayerCreateNPCEvent)2 Template (net.citizensnpcs.npc.Template)2 Age (net.citizensnpcs.trait.Age)2