Search in sources :

Example 51 with Command

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

the class NPCCommands method sheep.

@Command(aliases = { "npc" }, usage = "sheep (--color [color]) (--sheared [sheared])", desc = "Sets sheep modifiers", modifiers = { "sheep" }, min = 1, max = 1, permission = "citizens.npc.sheep")
@Requirements(selected = true, ownership = true, types = { EntityType.SHEEP })
public void sheep(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    SheepTrait trait = npc.getTrait(SheepTrait.class);
    boolean hasArg = false;
    if (args.hasValueFlag("sheared")) {
        trait.setSheared(Boolean.valueOf(args.getFlag("sheared")));
        hasArg = true;
    }
    if (args.hasValueFlag("color")) {
        DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
        if (color != null) {
            trait.setColor(color);
            Messaging.sendTr(sender, Messages.SHEEP_COLOR_SET, color.toString().toLowerCase());
        } else {
            Messaging.sendErrorTr(sender, Messages.INVALID_SHEEP_COLOR, Util.listValuesPretty(DyeColor.values()));
        }
        hasArg = true;
    }
    if (!hasArg) {
        throw new CommandException();
    }
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) DyeColor(org.bukkit.DyeColor) SheepTrait(net.citizensnpcs.trait.SheepTrait) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 52 with Command

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

the class NPCCommands method item.

@Command(aliases = { "npc" }, usage = "item [item] (data)", desc = "Sets the NPC's item", modifiers = { "item" }, min = 2, max = 3, flags = "", permission = "citizens.npc.item")
@Requirements(selected = true, ownership = true, types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME, EntityType.FALLING_BLOCK })
public void item(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Material mat = Material.matchMaterial(args.getString(1));
    if (mat == null)
        throw new CommandException(Messages.UNKNOWN_MATERIAL);
    int data = args.getInteger(2, 0);
    npc.data().setPersistent(NPC.ITEM_ID_METADATA, mat.name());
    npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
    switch(npc.getEntity().getType()) {
        case DROPPED_ITEM:
            ((org.bukkit.entity.Item) npc.getEntity()).getItemStack().setType(mat);
            break;
        case ITEM_FRAME:
            ((ItemFrame) npc.getEntity()).getItem().setType(mat);
            break;
        default:
            break;
    }
    if (npc.isSpawned()) {
        npc.despawn();
        npc.spawn(npc.getStoredLocation());
    }
    Messaging.sendTr(sender, Messages.ITEM_SET, Util.prettyEnum(mat));
}
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 53 with Command

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

the class NPCCommands method copy.

@Command(aliases = { "npc" }, usage = "copy (--name newname)", desc = "Copies an NPC", modifiers = { "copy" }, min = 1, max = 1, permission = "citizens.npc.copy")
public void copy(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String name = args.getFlag("name", npc.getFullName());
    NPC copy = npc.clone();
    if (!copy.getFullName().equals(name)) {
        copy.setName(name);
    }
    if (copy.isSpawned() && args.getSenderLocation() != null) {
        Location location = args.getSenderLocation();
        location.getChunk().load();
        copy.teleport(location, TeleportCause.COMMAND);
        copy.getTrait(CurrentLocation.class).setLocation(location);
    }
    CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy) : new CommandSenderCreateNPCEvent(sender, copy);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        event.getNPC().destroy();
        String reason = "Couldn't create NPC.";
        if (!event.getCancelReason().isEmpty())
            reason += " Reason: " + event.getCancelReason();
        throw new CommandException(reason);
    }
    Messaging.sendTr(sender, Messages.NPC_COPIED, npc.getName());
    selector.select(sender, copy);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) PlayerCreateNPCEvent(net.citizensnpcs.api.event.PlayerCreateNPCEvent) Player(org.bukkit.entity.Player) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) CommandSenderCreateNPCEvent(net.citizensnpcs.api.event.CommandSenderCreateNPCEvent) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command)

Example 54 with Command

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

the class TemplateCommands method apply.

@Command(aliases = { "template", "tpl" }, usage = "apply [template name] (id id2...)", desc = "Applies a template to the selected NPC", modifiers = { "apply" }, min = 2, permission = "citizens.templates.apply")
@Requirements
public void apply(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Template template = Template.byName(args.getString(1));
    if (template == null)
        throw new CommandException(Messages.TEMPLATE_MISSING);
    int appliedCount = 0;
    if (args.argsLength() == 2) {
        if (npc == null)
            throw new CommandException(Messaging.tr(Messages.COMMAND_MUST_HAVE_SELECTED));
        template.apply(npc);
        appliedCount++;
    } else {
        String joined = args.getJoinedStrings(2, ',');
        List<Integer> ids = Lists.newArrayList();
        for (String id : Splitter.on(',').trimResults().split(joined)) {
            int parsed = Integer.parseInt(id);
            ids.add(parsed);
        }
        Iterable<NPC> transformed = Iterables.transform(ids, new Function<Integer, NPC>() {

            @Override
            public NPC apply(@Nullable Integer arg0) {
                if (arg0 == null)
                    return null;
                return CitizensAPI.getNPCRegistry().getById(arg0);
            }
        });
        for (NPC toApply : transformed) {
            template.apply(toApply);
            appliedCount++;
        }
    }
    Messaging.sendTr(sender, Messages.TEMPLATE_APPLIED, appliedCount);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) CommandException(net.citizensnpcs.api.command.exception.CommandException) Template(net.citizensnpcs.npc.Template) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 55 with Command

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

the class TemplateCommands method create.

@Command(aliases = { "template", "tpl" }, usage = "create [template name] (-o)", desc = "Creates a template from the selected NPC", modifiers = { "create" }, min = 2, max = 2, flags = "o", permission = "citizens.templates.create")
public void create(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String name = args.getString(1);
    if (Template.byName(name) != null)
        throw new CommandException(Messages.TEMPLATE_CONFLICT);
    TemplateBuilder.create(name).from(npc).override(args.hasFlag('o')).buildAndSave();
    Messaging.sendTr(sender, Messages.TEMPLATE_CREATED);
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

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