Search in sources :

Example 26 with Command

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

the class NPCCommands method profession.

@Command(aliases = { "npc" }, usage = "profession|prof [profession]", desc = "Set a NPC's profession", modifiers = { "profession", "prof" }, min = 2, max = 2, permission = "citizens.npc.profession")
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER })
public void profession(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String profession = args.getString(1);
    Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
    if (parsed == null) {
        throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1), StringUtils.join(Profession.values(), ","));
    }
    npc.getTrait(VillagerProfession.class).setProfession(parsed);
    Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
}
Also used : Profession(org.bukkit.entity.Villager.Profession) VillagerProfession(net.citizensnpcs.trait.VillagerProfession) VillagerProfession(net.citizensnpcs.trait.VillagerProfession) 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 27 with Command

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

the class NPCCommands method slimeSize.

@Command(aliases = { "npc" }, usage = "size [size]", desc = "Sets the NPC's size", modifiers = { "size" }, min = 1, max = 2, permission = "citizens.npc.size")
@Requirements(selected = true, ownership = true, types = { EntityType.MAGMA_CUBE, EntityType.SLIME })
public void slimeSize(CommandContext args, CommandSender sender, NPC npc) {
    SlimeSize trait = npc.getTrait(SlimeSize.class);
    if (args.argsLength() <= 1) {
        trait.describe(sender);
        return;
    }
    int size = Math.max(-2, args.getInteger(1));
    trait.setSize(size);
    Messaging.sendTr(sender, Messages.SIZE_SET, npc.getName(), size);
}
Also used : SlimeSize(net.citizensnpcs.trait.SlimeSize) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 28 with Command

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

the class NPCCommands method list.

@Command(aliases = { "npc" }, usage = "list (page) ((-a) --owner (owner) --type (type) --char (char) --registry (name))", desc = "List NPCs", flags = "a", modifiers = { "list" }, min = 1, max = 2, permission = "citizens.npc.list")
@Requirements
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    NPCRegistry source = args.hasValueFlag("registry") ? CitizensAPI.getNamedNPCRegistry(args.getFlag("registry")) : npcRegistry;
    if (source == null)
        throw new CommandException();
    List<NPC> npcs = new ArrayList<NPC>();
    if (args.hasFlag('a')) {
        for (NPC add : source.sorted()) {
            npcs.add(add);
        }
    } else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
        for (NPC add : source.sorted()) {
            if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(sender)) {
                npcs.add(add);
            }
        }
    } else {
        if (args.hasValueFlag("owner")) {
            String name = args.getFlag("owner");
            for (NPC add : source.sorted()) {
                if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(name)) {
                    npcs.add(add);
                }
            }
        }
        if (args.hasValueFlag("type")) {
            EntityType type = Util.matchEntityType(args.getFlag("type"));
            if (type == null)
                throw new CommandException(Messages.COMMAND_INVALID_MOBTYPE, type);
            for (NPC add : source) {
                if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type)
                    npcs.add(add);
            }
        }
    }
    Paginator paginator = new Paginator().header("NPCs");
    paginator.addLine("<e>Key: <a>ID  <b>Name");
    for (int i = 0; i < npcs.size(); i += 2) {
        String line = "<a>" + npcs.get(i).getId() + "<b>  " + npcs.get(i).getName();
        if (npcs.size() >= i + 2)
            line += "      " + "<a>" + npcs.get(i + 1).getId() + "<b>  " + npcs.get(i + 1).getName();
        paginator.addLine(line);
    }
    int page = args.getInteger(1, 1);
    if (!paginator.sendPage(sender, page))
        throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) Owner(net.citizensnpcs.api.trait.trait.Owner) ArrayList(java.util.ArrayList) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 29 with Command

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

the class NPCCommands method moveto.

@Command(aliases = { "npc" }, usage = "moveto x:y:z:world | x y z world", desc = "Teleports a NPC to a given location", modifiers = "moveto", min = 1, permission = "citizens.npc.moveto")
public void moveto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    // Spawn the NPC if it isn't spawned to prevent NPEs
    if (!npc.isSpawned()) {
        npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
    }
    if (!npc.isSpawned()) {
        throw new CommandException("NPC could not be spawned.");
    }
    Location current = npc.getEntity().getLocation();
    Location to;
    if (args.argsLength() > 1) {
        String[] parts = Iterables.toArray(Splitter.on(':').split(args.getJoinedStrings(1, ':')), String.class);
        if (parts.length != 4 && parts.length != 3)
            throw new CommandException(Messages.MOVETO_FORMAT);
        double x = Double.parseDouble(parts[0]);
        double y = Double.parseDouble(parts[1]);
        double z = Double.parseDouble(parts[2]);
        World world = parts.length == 4 ? Bukkit.getWorld(parts[3]) : current.getWorld();
        if (world == null)
            throw new CommandException(Messages.WORLD_NOT_FOUND);
        to = new Location(world, x, y, z, current.getYaw(), current.getPitch());
    } else {
        to = current.clone();
        if (args.hasValueFlag("x"))
            to.setX(args.getFlagDouble("x"));
        if (args.hasValueFlag("y"))
            to.setY(args.getFlagDouble("y"));
        if (args.hasValueFlag("z"))
            to.setZ(args.getFlagDouble("z"));
        if (args.hasValueFlag("yaw"))
            to.setYaw((float) args.getFlagDouble("yaw"));
        if (args.hasValueFlag("pitch"))
            to.setPitch((float) args.getFlagDouble("pitch"));
        if (args.hasValueFlag("world")) {
            World world = Bukkit.getWorld(args.getFlag("world"));
            if (world == null)
                throw new CommandException(Messages.WORLD_NOT_FOUND);
            to.setWorld(world);
        }
    }
    npc.teleport(to, TeleportCause.COMMAND);
    Messaging.sendTr(sender, Messages.MOVETO_TELEPORTED, npc.getName(), to);
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) World(org.bukkit.World) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command)

Example 30 with Command

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

the class TraitCommands method configure.

@Command(aliases = { "traitc", "trc" }, usage = "[trait name] (flags)", desc = "Configures a trait", modifiers = { "*" }, min = 1, flags = "*", permission = "citizens.npc.trait-configure")
public void configure(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String traitName = args.getString(0);
    if (!sender.hasPermission("citizens.npc.trait-configure." + traitName) && !sender.hasPermission("citizens.npc.trait-configure.*"))
        throw new NoPermissionsException();
    Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(args.getString(0));
    if (clazz == null)
        throw new CommandException(Messages.TRAIT_NOT_FOUND);
    if (!CommandConfigurable.class.isAssignableFrom(clazz))
        throw new CommandException(Messages.TRAIT_NOT_CONFIGURABLE);
    if (!npc.hasTrait(clazz))
        throw new CommandException(Messages.TRAIT_NOT_FOUND_ON_NPC);
    CommandConfigurable trait = (CommandConfigurable) npc.getTrait(clazz);
    trait.configure(args);
}
Also used : NoPermissionsException(net.citizensnpcs.api.command.exception.NoPermissionsException) CommandException(net.citizensnpcs.api.command.exception.CommandException) CommandConfigurable(net.citizensnpcs.api.command.CommandConfigurable) 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