use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method shulker.
@Command(aliases = { "npc" }, usage = "shulker (--peek [peek] --color [color])", desc = "Sets shulker modifiers.", modifiers = { "shulker" }, min = 1, max = 1, permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
trait.setPeek(peek);
Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
hasArg = true;
}
if (args.hasValueFlag("color")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
if (color == null) {
Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values()));
return;
}
trait.setColor(color);
Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method bossbar.
@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
}
if (args.hasValueFlag("flags")) {
List<BarFlag> flags = Lists.newArrayList();
for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
BarFlag flag = Util.matchEnum(BarFlag.values(), s);
if (flag != null) {
flags.add(flag);
}
}
trait.setFlags(flags);
}
}
use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.
the class NPCCommandHandler method assignment.
/*
* ASSIGNMENT
*/
@Command(aliases = { "npc" }, usage = "assignment --set assignment_name (-r)", desc = "Controls the assignment for an NPC.", flags = "r", modifiers = { "assignment", "assign" }, min = 1, max = 3, permission = "denizen.npc.assign")
@Requirements(selected = true, ownership = true)
public void assignment(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.hasTrait(AssignmentTrait.class)) {
npc.addTrait(AssignmentTrait.class);
}
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
AssignmentTrait trait = npc.getTrait(AssignmentTrait.class);
if (args.hasValueFlag("set")) {
String script = args.getFlag("set").replace("\"", "");
if (trait.setAssignment(script, dPlayer.mirrorBukkitPlayer(player))) {
if (trait.hasAssignment()) {
Messaging.sendInfo(sender, npc.getName() + "'s assignment is now: '" + trait.getAssignment().getName() + "'.");
} else {
Messaging.sendInfo(sender, npc.getName() + "'s assignment was not able to be set.");
}
} else if (ScriptRegistry.containsScript(script)) {
Messaging.sendError(sender, "A script with that name exists, but it is not an assignment script!");
} else {
Messaging.sendError(sender, "Invalid assignment! Has the script sucessfully loaded, or has it been mispelled?");
}
return;
} else if (args.hasFlag('r')) {
trait.removeAssignment(dPlayer.mirrorBukkitPlayer(player));
Messaging.sendInfo(sender, npc.getName() + "'s assignment has been removed.");
return;
} else if (args.length() > 2 && args.getInteger(1, 0) < 1) {
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '--set name' to set an assignment script to this NPC.");
Messaging.send(sender, "<b>Example: /npc assignment --set \"Magic Shop\"");
Messaging.send(sender, "<f>Remove an assignment with '-r'.");
Messaging.send(sender, "<f>Note: Assigning a script will fire an 'On Assignment:' action.");
Messaging.send(sender, "");
return;
}
try {
trait.describe(sender, args.getInteger(1, 1));
} catch (net.citizensnpcs.api.command.exception.CommandException e) {
throw new CommandException(e.getMessage());
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method bossbar.
@Command(aliases = { "npc" }, usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", desc = "Edit bossbar properties", modifiers = { "bossbar" }, min = 1, max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
}
if (args.hasValueFlag("flags")) {
List<BarFlag> flags = Lists.newArrayList();
for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) {
BarFlag flag = Util.matchEnum(BarFlag.values(), s);
if (flag != null) {
flags.add(flag);
}
}
trait.setFlags(flags);
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method llama.
@Command(aliases = { "npc" }, usage = "llama (--color color) (--strength strength)", desc = "Sets llama modifiers", modifiers = { "llama" }, min = 1, max = 1, permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
String output = "";
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_LLAMA_COLOR, valid);
}
trait.setColor(color);
output += Messaging.tr(Messages.LLAMA_COLOR_SET, Util.prettyEnum(color));
}
if (args.hasValueFlag("strength")) {
trait.setStrength(Math.max(1, Math.min(5, args.getFlagInteger("strength"))));
output += Messaging.tr(Messages.LLAMA_STRENGTH_SET, args.getFlagInteger("strength"));
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
}
}
Aggregations