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