Search in sources :

Example 16 with Command

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

the class NPCCommands method speed.

@Command(aliases = { "npc" }, usage = "speed [speed]", desc = "Sets the movement speed of an NPC as a percentage", modifiers = { "speed" }, min = 2, max = 2, permission = "citizens.npc.speed")
public void speed(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    float newSpeed = (float) Math.abs(args.getDouble(1));
    if (newSpeed >= Setting.MAX_SPEED.asDouble())
        throw new CommandException(Messages.SPEED_MODIFIER_ABOVE_LIMIT);
    npc.getNavigator().getDefaultParameters().speedModifier(newSpeed);
    Messaging.sendTr(sender, Messages.SPEED_MODIFIER_SET, newSpeed);
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 17 with Command

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

the class NPCCommands method horse.

@Command(aliases = { "npc" }, usage = "horse (--color color) (--type type) (--style style) (-cb)", desc = "Sets horse modifiers", help = "Use the -c flag to make the horse have a chest, or the -b flag to stop them from having a chest.", modifiers = { "horse" }, min = 1, max = 1, flags = "cb", permission = "citizens.npc.horse")
@Requirements(selected = true, ownership = true, types = EntityType.HORSE)
public void horse(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    HorseModifiers horse = npc.getTrait(HorseModifiers.class);
    String output = "";
    if (args.hasFlag('c')) {
        horse.setCarryingChest(true);
        output += Messaging.tr(Messages.HORSE_CHEST_SET) + " ";
    } else if (args.hasFlag('b')) {
        horse.setCarryingChest(false);
        output += Messaging.tr(Messages.HORSE_CHEST_UNSET) + " ";
    }
    if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
        String colorRaw = args.getFlag("color", args.getFlag("colour"));
        Color color = Util.matchEnum(Color.values(), colorRaw);
        if (color == null) {
            String valid = Util.listValuesPretty(Color.values());
            throw new CommandException(Messages.INVALID_HORSE_COLOR, valid);
        }
        horse.setColor(color);
        output += Messaging.tr(Messages.HORSE_COLOR_SET, Util.prettyEnum(color));
    }
    if (args.hasValueFlag("style")) {
        Style style = Util.matchEnum(Style.values(), args.getFlag("style"));
        if (style == null) {
            String valid = Util.listValuesPretty(Style.values());
            throw new CommandException(Messages.INVALID_HORSE_STYLE, valid);
        }
        horse.setStyle(style);
        output += Messaging.tr(Messages.HORSE_STYLE_SET, Util.prettyEnum(style));
    }
    if (output.isEmpty()) {
        Messaging.sendTr(sender, Messages.HORSE_DESCRIBE, Util.prettyEnum(horse.getColor()), Util.prettyEnum(horse.getNPC().getEntity().getType()), Util.prettyEnum(horse.getStyle()));
    } else {
        sender.sendMessage(output);
    }
}
Also used : Color(org.bukkit.entity.Horse.Color) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Style(org.bukkit.entity.Horse.Style) HorseModifiers(net.citizensnpcs.trait.HorseModifiers) 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 18 with Command

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

the class NPCCommands method speak.

@Command(aliases = { "npc" }, usage = "speak message to speak --target npcid|player_name --type vocal_type", desc = "Uses the NPCs SpeechController to talk", modifiers = { "speak" }, min = 2, permission = "citizens.npc.speak")
public void speak(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String type = npc.getTrait(Speech.class).getDefaultVocalChord();
    String message = Colorizer.parseColors(args.getJoinedStrings(1));
    if (message.length() <= 0) {
        Messaging.send(sender, "Default Vocal Chord for " + npc.getName() + ": " + npc.getTrait(Speech.class).getDefaultVocalChord());
        return;
    }
    SpeechContext context = new SpeechContext(message);
    if (args.hasValueFlag("target")) {
        if (args.getFlag("target").matches("\\d+")) {
            NPC target = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(args.getFlag("target")));
            if (target != null)
                context.addRecipient(target.getEntity());
        } else {
            Player player = Bukkit.getPlayer(args.getFlag("target"));
            if (player != null) {
                context.addRecipient((Entity) player);
            }
        }
    }
    if (args.hasValueFlag("type")) {
        if (CitizensAPI.getSpeechFactory().isRegistered(args.getFlag("type")))
            type = args.getFlag("type");
    }
    npc.getDefaultSpeechController().speak(context, type);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) SpeechContext(net.citizensnpcs.api.ai.speech.SpeechContext) Speech(net.citizensnpcs.api.trait.trait.Speech) Command(net.citizensnpcs.api.command.Command)

Example 19 with Command

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

the class NPCCommands method metadata.

@Command(aliases = { "npc" }, usage = "metadata set|get|remove [key] (value) (-t(emporary))", desc = "Manages NPC metadata", modifiers = { "metadata" }, flags = "t", min = 2, max = 4, permission = "citizens.npc.metadata")
@Requirements(selected = true, ownership = true)
public void metadata(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String command = args.getString(1).toLowerCase();
    if (command.equals("set")) {
        if (args.argsLength() != 4)
            throw new CommandException();
        if (args.hasFlag('t')) {
            npc.data().set(args.getString(2), args.getString(3));
        } else {
            npc.data().setPersistent(args.getString(2), args.getString(3));
        }
        Messaging.sendTr(sender, Messages.METADATA_SET, args.getString(2), args.getString(3));
    } else if (args.equals("get")) {
        if (args.argsLength() != 3) {
            throw new CommandException();
        }
        Messaging.send(sender, npc.data().get(args.getString(2), "null"));
    } else if (args.equals("remove")) {
        if (args.argsLength() != 3) {
            throw new CommandException();
        }
        npc.data().remove(args.getString(3));
        Messaging.sendTr(sender, Messages.METADATA_UNSET, args.getString(2));
    }
}
Also used : 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 20 with Command

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

the class NPCCommands method ocelot.

@Command(aliases = { "npc" }, usage = "ocelot (--type type) (-s(itting), -n(ot sitting))", desc = "Set the ocelot type of an NPC and whether it is sitting", modifiers = { "ocelot" }, min = 1, max = 1, requiresFlags = true, flags = "sn", permission = "citizens.npc.ocelot")
@Requirements(selected = true, ownership = true, types = { EntityType.OCELOT })
public void ocelot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    OcelotModifiers trait = npc.getTrait(OcelotModifiers.class);
    if (args.hasFlag('s')) {
        trait.setSitting(true);
    } else if (args.hasFlag('n')) {
        trait.setSitting(false);
    }
    if (args.hasValueFlag("type")) {
        Ocelot.Type type = Util.matchEnum(Ocelot.Type.values(), args.getFlag("type"));
        if (type == null) {
            String valid = Util.listValuesPretty(Ocelot.Type.values());
            throw new CommandException(Messages.INVALID_OCELOT_TYPE, valid);
        }
        trait.setType(type);
    }
}
Also used : Ocelot(org.bukkit.entity.Ocelot) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) OcelotModifiers(net.citizensnpcs.trait.OcelotModifiers) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

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