Search in sources :

Example 46 with Command

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

the class NPCCommands method rabbitType.

@Command(aliases = { "npc" }, usage = "rabbittype [type]", desc = "Set the Type of a Rabbit NPC", modifiers = { "rabbittype", "rbtype" }, min = 2, permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Rabbit.Type type;
    try {
        type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
    } catch (IllegalArgumentException ex) {
        throw new CommandException(Messages.INVALID_RABBIT_TYPE, StringUtils.join(Rabbit.Type.values(), ","));
    }
    npc.getTrait(RabbitType.class).setType(type);
    Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
}
Also used : RabbitType(net.citizensnpcs.trait.RabbitType) Rabbit(org.bukkit.entity.Rabbit) 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 47 with Command

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

the class NPCCommands method skin.

@Command(aliases = { "npc" }, usage = "skin (-c -l(atest)) [name]", desc = "Sets an NPC's skin name. Use -l to set the skin to always update to the latest", modifiers = { "skin" }, min = 1, max = 2, flags = "cl", permission = "citizens.npc.skin")
@Requirements(types = EntityType.PLAYER, selected = true, ownership = true)
public void skin(final CommandContext args, final CommandSender sender, final NPC npc) throws CommandException {
    String skinName = npc.getName();
    if (args.hasFlag('c')) {
        npc.data().remove(NPC.PLAYER_SKIN_UUID_METADATA);
    } else {
        if (args.argsLength() != 2)
            throw new CommandException(Messages.SKIN_REQUIRED);
        npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, args.getString(1));
        if (args.hasFlag('l')) {
            npc.data().setPersistent(NPC.PLAYER_SKIN_USE_LATEST, true);
        }
        skinName = args.getString(1);
    }
    Messaging.sendTr(sender, Messages.SKIN_SET, npc.getName(), skinName);
    if (npc.isSpawned()) {
        SkinnableEntity skinnable = npc.getEntity() instanceof SkinnableEntity ? (SkinnableEntity) npc.getEntity() : null;
        if (skinnable != null) {
            skinnable.setSkinName(skinName, true);
        }
    }
}
Also used : SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) 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 48 with Command

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

the class NPCCommands method owner.

@Command(aliases = { "npc" }, usage = "owner [name]", desc = "Set the owner of an NPC", modifiers = { "owner" }, min = 1, max = 2, permission = "citizens.npc.owner")
public void owner(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Owner ownerTrait = npc.getTrait(Owner.class);
    if (args.argsLength() == 1) {
        Messaging.sendTr(sender, Messages.NPC_OWNER, npc.getName(), ownerTrait.getOwner());
        return;
    }
    String name = args.getString(1);
    if (ownerTrait.isOwnedBy(name))
        throw new CommandException(Messages.ALREADY_OWNER, name, npc.getName());
    ownerTrait.setOwner(name);
    boolean serverOwner = name.equalsIgnoreCase(Owner.SERVER);
    Messaging.sendTr(sender, serverOwner ? Messages.OWNER_SET_SERVER : Messages.OWNER_SET, npc.getName(), name);
}
Also used : Owner(net.citizensnpcs.api.trait.trait.Owner) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 49 with Command

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

the class NPCCommands method tpto.

@Command(aliases = { "npc" }, usage = "tpto [player name|npc id] [player name|npc id]", desc = "Teleport an NPC or player to another NPC or player", modifiers = { "tpto" }, min = 3, max = 3, permission = "citizens.npc.tpto")
@Requirements
public void tpto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Entity from = null, to = null;
    if (npc != null) {
        from = npc.getEntity();
    }
    boolean firstWasPlayer = false;
    try {
        int id = args.getInteger(1);
        NPC fromNPC = CitizensAPI.getNPCRegistry().getById(id);
        if (fromNPC != null) {
            from = fromNPC.getEntity();
        }
    } catch (NumberFormatException e) {
        from = Bukkit.getPlayerExact(args.getString(1));
        firstWasPlayer = true;
    }
    try {
        int id = args.getInteger(2);
        NPC toNPC = CitizensAPI.getNPCRegistry().getById(id);
        if (toNPC != null) {
            to = toNPC.getEntity();
        }
    } catch (NumberFormatException e) {
        if (!firstWasPlayer) {
            to = Bukkit.getPlayerExact(args.getString(2));
        }
    }
    if (from == null)
        throw new CommandException(Messages.FROM_ENTITY_NOT_FOUND);
    if (to == null)
        throw new CommandException(Messages.TO_ENTITY_NOT_FOUND);
    from.teleport(to);
    Messaging.sendTr(sender, Messages.TPTO_SUCCESS);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Entity(org.bukkit.entity.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) 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 50 with Command

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

the class NPCCommands method spawn.

@Command(aliases = { "npc" }, usage = "spawn (id|name) -l(oad chunks)", desc = "Spawn an existing NPC", modifiers = { "spawn" }, min = 1, max = 2, flags = "l", permission = "citizens.npc.spawn")
@Requirements(ownership = true)
public void spawn(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
    NPCCommandSelector.Callback callback = new NPCCommandSelector.Callback() {

        @Override
        public void run(NPC respawn) throws CommandException {
            if (respawn == null) {
                if (args.argsLength() > 1) {
                    throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getString(1));
                } else {
                    throw new CommandException(CommandMessages.MUST_HAVE_SELECTED);
                }
            }
            if (respawn.isSpawned()) {
                throw new CommandException(Messages.NPC_ALREADY_SPAWNED, respawn.getName());
            }
            Location location = respawn.getTrait(CurrentLocation.class).getLocation();
            if (location == null || args.hasValueFlag("location")) {
                if (args.getSenderLocation() == null)
                    throw new CommandException(Messages.NO_STORED_SPAWN_LOCATION);
                location = args.getSenderLocation();
            }
            if (args.hasFlag('l') && !Util.isLoaded(location)) {
                location.getChunk().load();
            }
            if (respawn.spawn(location)) {
                selector.select(sender, respawn);
                Messaging.sendTr(sender, Messages.NPC_SPAWNED, respawn.getName());
            }
        }
    };
    if (args.argsLength() > 1) {
        NPCCommandSelector.startWithCallback(callback, npcRegistry, sender, args, args.getString(1));
    } else {
        callback.run(npc);
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

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