Search in sources :

Example 6 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 7 with Command

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

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

the class NPCCommands method controllable.

@Command(aliases = { "npc" }, usage = "controllable|control (-m(ount),-y,-n,-o)", desc = "Toggles whether the NPC can be ridden and controlled", modifiers = { "controllable", "control" }, min = 1, max = 1, flags = "myno")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable." + npc.getEntity().getType().name().toLowerCase().replace("_", ""))) || !sender.hasPermission("citizens.npc.controllable"))
        throw new NoPermissionsException();
    if (!npc.hasTrait(Controllable.class)) {
        npc.addTrait(new Controllable(false));
    }
    Controllable trait = npc.getTrait(Controllable.class);
    boolean enabled = trait.toggle();
    if (args.hasFlag('y')) {
        enabled = trait.setEnabled(true);
    } else if (args.hasFlag('n')) {
        enabled = trait.setEnabled(false);
    }
    trait.setOwnerRequired(args.hasFlag('o'));
    String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;
    Messaging.sendTr(sender, key, npc.getName());
    if (enabled && args.hasFlag('m') && sender instanceof Player) {
        trait.mount((Player) sender);
    }
}
Also used : Player(org.bukkit.entity.Player) Controllable(net.citizensnpcs.trait.Controllable) NoPermissionsException(net.citizensnpcs.api.command.exception.NoPermissionsException) Command(net.citizensnpcs.api.command.Command)

Example 9 with Command

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

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

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