Search in sources :

Example 11 with Command

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

the class NPCCommands method gamemode.

@Command(aliases = { "npc" }, usage = "gamemode [gamemode]", desc = "Changes the gamemode", modifiers = { "gamemode" }, min = 1, max = 2, permission = "citizens.npc.gravity")
@Requirements(selected = true, ownership = true, types = { EntityType.PLAYER })
public void gamemode(CommandContext args, CommandSender sender, NPC npc) {
    Player player = (Player) npc.getEntity();
    if (args.argsLength() == 1) {
        Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(), player.getGameMode().name().toLowerCase());
        return;
    }
    GameMode mode = null;
    try {
        int value = args.getInteger(1);
        mode = GameMode.getByValue(value);
    } catch (NumberFormatException ex) {
        try {
            mode = GameMode.valueOf(args.getString(1));
        } catch (IllegalArgumentException e) {
        }
    }
    if (mode == null) {
        Messaging.sendErrorTr(sender, Messages.GAMEMODE_INVALID, args.getString(1));
        return;
    }
    player.setGameMode(mode);
    Messaging.sendTr(sender, Messages.GAMEMODE_SET, mode.name().toLowerCase());
}
Also used : GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 12 with Command

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

the class NPCCommands method age.

@Command(aliases = { "npc" }, usage = "age [age] (-l)", desc = "Set the age of a NPC", help = Messages.COMMAND_AGE_HELP, flags = "l", modifiers = { "age" }, min = 1, max = 2, permission = "citizens.npc.age")
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (!npc.isSpawned() || (!(npc.getEntity() instanceof Ageable) && !(npc.getEntity() instanceof Zombie)))
        throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED, npc.getName());
    Age trait = npc.getTrait(Age.class);
    boolean toggleLock = args.hasFlag('l');
    if (toggleLock) {
        Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
    }
    if (args.argsLength() <= 1) {
        if (!toggleLock)
            trait.describe(sender);
        return;
    }
    int age = 0;
    try {
        age = args.getInteger(1);
        if (age > 0) {
            throw new CommandException(Messages.INVALID_AGE);
        }
        Messaging.sendTr(sender, Messages.AGE_SET_NORMAL, npc.getName(), age);
    } catch (NumberFormatException ex) {
        if (args.getString(1).equalsIgnoreCase("baby")) {
            age = -24000;
            Messaging.sendTr(sender, Messages.AGE_SET_BABY, npc.getName());
        } else if (args.getString(1).equalsIgnoreCase("adult")) {
            age = 0;
            Messaging.sendTr(sender, Messages.AGE_SET_ADULT, npc.getName());
        } else
            throw new CommandException(Messages.INVALID_AGE);
    }
    trait.setAge(age);
}
Also used : Zombie(org.bukkit.entity.Zombie) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Ageable(org.bukkit.entity.Ageable) Age(net.citizensnpcs.trait.Age) Command(net.citizensnpcs.api.command.Command)

Example 13 with Command

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

the class NPCCommands method rename.

@Command(aliases = { "npc" }, usage = "rename [name]", desc = "Rename a NPC", modifiers = { "rename" }, min = 2, permission = "citizens.npc.rename")
public void rename(CommandContext args, CommandSender sender, NPC npc) {
    String oldName = npc.getName();
    String newName = Colorizer.parseColors(args.getJoinedStrings(1));
    int nameLength = npc.getTrait(MobType.class).getType() == EntityType.PLAYER ? 46 : 64;
    if (newName.length() > nameLength) {
        Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG);
        newName = newName.substring(0, nameLength);
    }
    Location prev = npc.isSpawned() ? npc.getEntity().getLocation() : null;
    npc.despawn(DespawnReason.PENDING_RESPAWN);
    npc.setName(newName);
    if (prev != null) {
        npc.spawn(prev);
    }
    Messaging.sendTr(sender, Messages.NPC_RENAMED, oldName, newName);
}
Also used : MobType(net.citizensnpcs.api.trait.trait.MobType) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command)

Example 14 with Command

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

the class NPCCommands method npc.

@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "citizens.npc.info")
public void npc(CommandContext args, CommandSender sender, final NPC npc) {
    Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
    Messaging.send(sender, "    <a>ID: <e>" + npc.getId());
    Messaging.send(sender, "    <a>Type: <e>" + npc.getTrait(MobType.class).getType());
    if (npc.isSpawned()) {
        Location loc = npc.getEntity().getLocation();
        String format = "    <a>Spawned at <e>%d, %d, %d <a>in world<e> %s";
        Messaging.send(sender, String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName()));
    }
    Messaging.send(sender, "    <a>Traits<e>");
    for (Trait trait : npc.getTraits()) {
        if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
            continue;
        String message = "     <e>- <a>" + trait.getName();
        Messaging.send(sender, message);
    }
}
Also used : Trait(net.citizensnpcs.api.trait.Trait) WitherTrait(net.citizensnpcs.trait.WitherTrait) SheepTrait(net.citizensnpcs.trait.SheepTrait) ScriptTrait(net.citizensnpcs.trait.ScriptTrait) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) MobType(net.citizensnpcs.api.trait.trait.MobType) Location(org.bukkit.Location) CurrentLocation(net.citizensnpcs.trait.CurrentLocation) Command(net.citizensnpcs.api.command.Command)

Example 15 with Command

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

the class NPCCommands method type.

@Command(aliases = { "npc" }, usage = "type [type]", desc = "Sets an NPC's entity type", modifiers = { "type" }, min = 2, max = 2, permission = "citizens.npc.type")
public void type(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    EntityType type = Util.matchEntityType(args.getString(1));
    if (type == null)
        throw new CommandException(Messages.INVALID_ENTITY_TYPE, args.getString(1));
    npc.setBukkitEntityType(type);
    Messaging.sendTr(sender, Messages.ENTITY_TYPE_SET, npc.getName(), args.getString(1));
}
Also used : EntityType(org.bukkit.entity.EntityType) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) 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