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);
}
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);
}
}
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);
}
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));
}
}
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);
}
}
Aggregations