This commit is contained in:
aPunch 2012-03-21 05:45:05 -05:00
parent 785f353bae
commit 7521e1765d
4 changed files with 163 additions and 130 deletions

View File

@ -31,7 +31,14 @@ public class AdminCommands {
Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite()); Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
} }
@Command(aliases = { "citizens" }, usage = "reload", desc = "Reload Citizens", modifiers = { "reload" }, min = 1, max = 1, permission = "admin") @Command(
aliases = { "citizens" },
usage = "reload",
desc = "Reload Citizens",
modifiers = { "reload" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand @ServerCommand
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Messaging.send(sender, "<e>Reloading Citizens..."); Messaging.send(sender, "<e>Reloading Citizens...");
@ -44,7 +51,14 @@ public class AdminCommands {
} }
} }
@Command(aliases = { "citizens" }, usage = "save", desc = "Save NPCs", modifiers = { "save" }, min = 1, max = 1, permission = "admin") @Command(
aliases = { "citizens" },
usage = "save",
desc = "Save NPCs",
modifiers = { "save" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand @ServerCommand
public void save(CommandContext args, CommandSender sender, NPC npc) { public void save(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, "<e>Saving Citizens..."); Messaging.send(sender, "<e>Saving Citizens...");

View File

@ -15,19 +15,40 @@ import org.bukkit.entity.Player;
@Requirements(selected = true, ownership = true) @Requirements(selected = true, ownership = true)
public class EditorCommands { public class EditorCommands {
@Command(aliases = { "npc" }, usage = "equip", desc = "Toggle the equipment editor", modifiers = { "equip" }, min = 1, max = 1, permission = "npc.edit.equip") @Command(
aliases = { "npc" },
usage = "equip",
desc = "Toggle the equipment editor",
modifiers = { "equip" },
min = 1,
max = 1,
permission = "npc.edit.equip")
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG, @Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG,
EntityType.SHEEP }) EntityType.SHEEP })
public void equip(CommandContext args, Player player, NPC npc) { public void equip(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, new EquipmentEditor(player, npc)); Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
} }
@Command(aliases = { "npc" }, usage = "path", desc = "Toggle the waypoint editor", modifiers = { "path" }, min = 1, max = 1, permission = "npc.edit.path") @Command(
aliases = { "npc" },
usage = "path",
desc = "Toggle the waypoint editor",
modifiers = { "path" },
min = 1,
max = 1,
permission = "npc.edit.path")
public void path(CommandContext args, Player player, NPC npc) { public void path(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player)); Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
} }
@Command(aliases = { "npc" }, usage = "text", desc = "Toggle the text editor", modifiers = { "text" }, min = 1, max = 1, permission = "npc.edit.text") @Command(
aliases = { "npc" },
usage = "text",
desc = "Toggle the text editor",
modifiers = { "text" },
min = 1,
max = 1,
permission = "npc.edit.text")
public void text(CommandContext args, Player player, NPC npc) { public void text(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player)); Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
} }

View File

@ -26,13 +26,13 @@ public class HelpCommands {
} }
@Command( @Command(
aliases = { "citizens" }, aliases = { "citizens" },
usage = "help (page)", usage = "help (page)",
desc = "Citizens help menu", desc = "Citizens help menu",
modifiers = { "help" }, modifiers = { "help" },
min = 1, min = 1,
max = 2, max = 2,
permission = "help") permission = "help")
@Requirements @Requirements
@ServerCommand @ServerCommand
public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
@ -45,13 +45,13 @@ public class HelpCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "help (page)", usage = "help (page)",
desc = "NPC help menu", desc = "NPC help menu",
modifiers = { "help" }, modifiers = { "help" },
min = 1, min = 1,
max = 2, max = 2,
permission = "npc.help") permission = "npc.help")
@Requirements @Requirements
@ServerCommand @ServerCommand
public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {

View File

@ -48,12 +48,12 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "character [character]", usage = "character [character]",
desc = "Set the character of a NPC", desc = "Set the character of a NPC",
modifiers = { "character" }, modifiers = { "character" },
min = 2, min = 2,
max = 2) max = 2)
public void character(CommandContext args, Player player, NPC npc) throws CommandException { public void character(CommandContext args, Player player, NPC npc) throws CommandException {
String name = args.getString(1).toLowerCase(); String name = args.getString(1).toLowerCase();
Character character = characterManager.getCharacter(name); Character character = characterManager.getCharacter(name);
@ -77,14 +77,14 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "create [name] (--type (type) --char (char))", usage = "create [name] ((-b) --type (type) --char (char))",
desc = "Create a new NPC", desc = "Create a new NPC",
flags = "b", flags = "b",
modifiers = { "create" }, modifiers = { "create" },
min = 2, min = 2,
max = 5, max = 5,
permission = "npc.create") permission = "npc.create")
@Requirements @Requirements
public void create(CommandContext args, Player player, NPC npc) { public void create(CommandContext args, Player player, NPC npc) {
String name = args.getString(1); String name = args.getString(1);
@ -154,13 +154,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "despawn", usage = "despawn",
desc = "Despawn a NPC", desc = "Despawn a NPC",
modifiers = { "despawn" }, modifiers = { "despawn" },
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.despawn") permission = "npc.despawn")
public void despawn(CommandContext args, Player player, NPC npc) { public void despawn(CommandContext args, Player player, NPC npc) {
npc.getTrait(Spawned.class).setSpawned(false); npc.getTrait(Spawned.class).setSpawned(false);
npc.despawn(); npc.despawn();
@ -168,22 +168,21 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))", usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))",
desc = "List NPCs", desc = "List NPCs",
flags = "a", flags = "a",
modifiers = { "list" }, modifiers = { "list" },
min = 1, min = 1,
max = 2, max = 2,
permission = "npc.list") permission = "npc.list")
@Requirements @Requirements
public void list(CommandContext args, Player player, NPC npc) throws CommandException { public void list(CommandContext args, Player player, NPC npc) throws CommandException {
List<NPC> npcs = new ArrayList<NPC>(); List<NPC> npcs = new ArrayList<NPC>();
if (args.hasFlag('a')) { if (args.hasFlag('a')) {
for (NPC add : npcManager) { for (NPC add : npcManager)
npcs.add(add); npcs.add(add);
}
} else if (args.getValueFlags().size() == 0 && args.argsLength() == 1 || args.argsLength() == 2) { } else if (args.getValueFlags().size() == 0 && args.argsLength() == 1 || args.argsLength() == 2) {
for (NPC add : npcManager) { for (NPC add : npcManager) {
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwner(player)) if (!npcs.contains(add) && add.getTrait(Owner.class).isOwner(player))
@ -201,9 +200,8 @@ public class NPCCommands {
if (args.hasValueFlag("type")) { if (args.hasValueFlag("type")) {
String type = args.getFlag("type"); String type = args.getFlag("type");
if (EntityType.fromName(type.replace('-', '_')) == null) { if (EntityType.fromName(type.replace('-', '_')) == null)
throw new CommandException("'" + type + "' is not a valid mob type."); throw new CommandException("'" + type + "' is not a valid mob type.");
}
for (NPC add : npcManager) { for (NPC add : npcManager) {
if (!npcs.contains(add) && add.getTrait(MobType.class).getType().equalsIgnoreCase(type)) if (!npcs.contains(add) && add.getTrait(MobType.class).getType().equalsIgnoreCase(type))
@ -225,7 +223,7 @@ public class NPCCommands {
Paginator paginator = new Paginator().header("NPCs"); Paginator paginator = new Paginator().header("NPCs");
paginator.addLine("<e>Key: <a>ID <b>Name"); paginator.addLine("<e>Key: <a>ID <b>Name");
for (int i = 0; i < npcs.size(); i += 2) {// 0,2,4,6,etc, size=3 for (int i = 0; i < npcs.size(); i += 2) {
String line = "<a>" + npcs.get(i).getId() + "<b> " + npcs.get(i).getName(); String line = "<a>" + npcs.get(i).getId() + "<b> " + npcs.get(i).getName();
if (npcs.size() >= i + 2) if (npcs.size() >= i + 2)
line += " " + "<a>" + npcs.get(i + 1).getId() + "<b> " + npcs.get(i + 1).getName(); line += " " + "<a>" + npcs.get(i + 1).getId() + "<b> " + npcs.get(i + 1).getName();
@ -238,13 +236,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "lookclose", usage = "lookclose",
desc = "Toggle whether a NPC will look when a player is near", desc = "Toggle whether a NPC will look when a player is near",
modifiers = { "lookclose", "look", "rotate" }, modifiers = { "lookclose", "look", "rotate" },
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.lookclose") permission = "npc.lookclose")
public void lookClose(CommandContext args, Player player, NPC npc) { public void lookClose(CommandContext args, Player player, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will " String msg = StringHelper.wrap(npc.getName()) + " will "
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate"); + (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
@ -261,13 +259,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "owner [name]", usage = "owner [name]",
desc = "Set the owner of an NPC", desc = "Set the owner of an NPC",
modifiers = { "owner" }, modifiers = { "owner" },
min = 1, min = 1,
max = 2, max = 2,
permission = "npc.owner") permission = "npc.owner")
public void owner(CommandContext args, Player player, NPC npc) throws CommandException { public void owner(CommandContext args, Player player, NPC npc) throws CommandException {
if (args.argsLength() == 1) { if (args.argsLength() == 1) {
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s Owner: ") Messaging.send(player, StringHelper.wrap(npc.getName() + "'s Owner: ")
@ -283,12 +281,12 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "remove (all)", usage = "remove (all)",
desc = "Remove a NPC", desc = "Remove a NPC",
modifiers = { "remove" }, modifiers = { "remove" },
min = 1, min = 1,
max = 2) max = 2)
@Requirements @Requirements
public void remove(CommandContext args, Player player, NPC npc) throws CommandException { public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
if (args.argsLength() == 2) { if (args.argsLength() == 2) {
@ -311,13 +309,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "rename [name]", usage = "rename [name]",
desc = "Rename a NPC", desc = "Rename a NPC",
modifiers = { "rename" }, modifiers = { "rename" },
min = 2, min = 2,
max = 2, max = 2,
permission = "npc.rename") permission = "npc.rename")
public void rename(CommandContext args, Player player, NPC npc) { public void rename(CommandContext args, Player player, NPC npc) {
String oldName = npc.getName(); String oldName = npc.getName();
String newName = args.getString(1); String newName = args.getString(1);
@ -332,13 +330,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "select [id]", usage = "select [id]",
desc = "Select a NPC with the given ID", desc = "Select a NPC with the given ID",
modifiers = { "select" }, modifiers = { "select" },
min = 2, min = 2,
max = 2, max = 2,
permission = "npc.select") permission = "npc.select")
@Requirements(ownership = true) @Requirements(ownership = true)
public void select(CommandContext args, Player player, NPC npc) throws CommandException { public void select(CommandContext args, Player player, NPC npc) throws CommandException {
NPC toSelect = npcManager.getNPC(args.getInteger(1)); NPC toSelect = npcManager.getNPC(args.getInteger(1));
@ -351,13 +349,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "spawn [id]", usage = "spawn [id]",
desc = "Spawn an existing NPC", desc = "Spawn an existing NPC",
modifiers = { "spawn" }, modifiers = { "spawn" },
min = 2, min = 2,
max = 2, max = 2,
permission = "npc.spawn") permission = "npc.spawn")
@Requirements @Requirements
public void spawn(CommandContext args, Player player, NPC npc) throws CommandException { public void spawn(CommandContext args, Player player, NPC npc) throws CommandException {
NPC respawn = npcManager.getNPC(args.getInteger(1)); NPC respawn = npcManager.getNPC(args.getInteger(1));
@ -377,13 +375,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "tp", usage = "tp",
desc = "Teleport to a NPC", desc = "Teleport to a NPC",
modifiers = { "tp", "teleport" }, modifiers = { "tp", "teleport" },
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.tp") permission = "npc.tp")
public void tp(CommandContext args, Player player, NPC npc) { public void tp(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -393,13 +391,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "tphere", usage = "tphere",
desc = "Teleport a NPC to your location", desc = "Teleport a NPC to your location",
modifiers = { "tphere" }, modifiers = { "tphere" },
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.tphere") permission = "npc.tphere")
public void tphere(CommandContext args, Player player, NPC npc) { public void tphere(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -409,13 +407,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "power", usage = "power",
desc = "Toggle a creeper NPC as powered", desc = "Toggle a creeper NPC as powered",
modifiers = { "power" }, modifiers = { "power" },
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.power") permission = "npc.power")
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER }) @Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, Player player, NPC npc) { public void power(CommandContext args, Player player, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will " String msg = StringHelper.wrap(npc.getName()) + " will "
@ -424,13 +422,13 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "profession [profession]", usage = "profession [profession]",
desc = "Set a NPC's profession", desc = "Set a NPC's profession",
modifiers = { "profession" }, modifiers = { "profession" },
min = 2, min = 2,
max = 2, max = 2,
permission = "npc.profession") permission = "npc.profession")
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER }) @Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER })
public void profession(CommandContext args, Player player, NPC npc) throws CommandException { public void profession(CommandContext args, Player player, NPC npc) throws CommandException {
String profession = args.getString(1); String profession = args.getString(1);
@ -446,14 +444,14 @@ public class NPCCommands {
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "age [age] (-l)", usage = "age [age] (-l)",
desc = "Set the age of a NPC", desc = "Set the age of a NPC",
flags = "l", flags = "l",
modifiers = { "age" }, modifiers = { "age" },
min = 1, min = 1,
max = 2, max = 2,
permission = "npc.age") permission = "npc.age")
@Requirements(selected = true, ownership = true, types = { EntityType.CHICKEN, EntityType.COW, EntityType.OCELOT, @Requirements(selected = true, ownership = true, types = { EntityType.CHICKEN, EntityType.COW, EntityType.OCELOT,
EntityType.PIG, EntityType.SHEEP, EntityType.VILLAGER, EntityType.WOLF }) EntityType.PIG, EntityType.SHEEP, EntityType.VILLAGER, EntityType.WOLF })
public void age(CommandContext args, Player player, NPC npc) throws CommandException { public void age(CommandContext args, Player player, NPC npc) throws CommandException {