added owner command, fixed help menu bug

This commit is contained in:
aPunch 2012-02-26 03:42:55 -06:00
parent 05acb6d50a
commit 9da9c6c806
3 changed files with 35 additions and 14 deletions

View File

@ -58,7 +58,7 @@ public class HelpCommands {
private boolean sendPage(Player player, String baseCommand, int page) { private boolean sendPage(Player player, String baseCommand, int page) {
List<String> lines = getLines(player, baseCommand); List<String> lines = getLines(player, baseCommand);
int pages = (lines.size() / LINES_PER_PAGE == 0) ? 1 : lines.size() / LINES_PER_PAGE; int pages = (int) ((lines.size() / LINES_PER_PAGE == 0) ? 1 : Math.ceil((double) lines.size() / LINES_PER_PAGE));
if (page < 0 || page > pages) if (page < 0 || page > pages)
return false; return false;
@ -70,8 +70,8 @@ public class HelpCommands {
+ " Help <f>" + page + "/" + pages)); + " Help <f>" + page + "/" + pages));
if (lines.size() < endIndex) if (lines.size() < endIndex)
endIndex = lines.size() - 1; endIndex = lines.size();
for (String line : lines.subList(startIndex, endIndex == -1 ? 0 : endIndex)) for (String line : lines.subList(startIndex, endIndex))
Messaging.send(player, line); Messaging.send(player, line);
return true; return true;
} }
@ -85,6 +85,7 @@ public class HelpCommands {
|| (!player.hasPermission("citizens.admin") && !player || (!player.hasPermission("citizens.admin") && !player
.hasPermission("citizens." + cmd.permission()))) .hasPermission("citizens." + cmd.permission())))
continue; continue;
lines.add("<7>/<c>" + cmd.aliases()[0] + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>" lines.add("<7>/<c>" + cmd.aliases()[0] + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>"
+ cmd.desc()); + cmd.desc());
if (cmd.modifiers().length > 1) if (cmd.modifiers().length > 1)

View File

@ -33,7 +33,7 @@ public class NPCCommands {
} }
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0) @Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0)
public void showInfo(CommandContext args, Player player, NPC npc) { public void npc(CommandContext args, Player player, NPC npc) {
Messaging.send(player, StringHelper.wrapHeader(npc.getName())); Messaging.send(player, StringHelper.wrapHeader(npc.getName()));
Messaging.send(player, " <a>ID: <e>" + npc.getId()); Messaging.send(player, " <a>ID: <e>" + npc.getId());
Messaging.send(player, " <a>Character: <e>" Messaging.send(player, " <a>Character: <e>"
@ -50,7 +50,7 @@ public class NPCCommands {
max = 5, max = 5,
permission = "npc.create") permission = "npc.create")
@Requirements @Requirements
public void createNPC(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);
if (name.length() > 16) { if (name.length() > 16) {
Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened."); Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened.");
@ -100,7 +100,7 @@ public class NPCCommands {
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.despawn") permission = "npc.despawn")
public void despawnNPC(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();
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + "."); Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
@ -114,7 +114,7 @@ public class NPCCommands {
min = 1, min = 1,
max = 2) max = 2)
@Requirements @Requirements
public void removeNPC(CommandContext args, Player player, NPC npc) { public void remove(CommandContext args, Player player, NPC npc) {
if (args.argsLength() == 2) { if (args.argsLength() == 2) {
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin")) { if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin")) {
Messaging.sendError(player, "You don't have permission to execute that command."); Messaging.sendError(player, "You don't have permission to execute that command.");
@ -148,7 +148,7 @@ public class NPCCommands {
min = 2, min = 2,
max = 2, max = 2,
permission = "npc.rename") permission = "npc.rename")
public void renameNPC(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);
if (newName.length() > 16) { if (newName.length() > 16) {
@ -169,7 +169,7 @@ public class NPCCommands {
max = 2, max = 2,
permission = "npc.select") permission = "npc.select")
@Requirements(ownership = true) @Requirements(ownership = true)
public void selectNPC(CommandContext args, Player player, NPC npc) { public void select(CommandContext args, Player player, NPC npc) {
NPC toSelect = npcManager.getNPC(args.getInteger(1)); NPC toSelect = npcManager.getNPC(args.getInteger(1));
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) { if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) {
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned."); Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
@ -190,7 +190,7 @@ public class NPCCommands {
modifiers = { "character" }, modifiers = { "character" },
min = 2, min = 2,
max = 2) max = 2)
public void setNPCCharacter(CommandContext args, Player player, NPC npc) { public void character(CommandContext args, Player player, NPC npc) {
String name = args.getString(1).toLowerCase(); String name = args.getString(1).toLowerCase();
Character character = characterManager.getInstance(name, npc); Character character = characterManager.getInstance(name, npc);
if (character == null) { if (character == null) {
@ -211,6 +211,25 @@ public class NPCCommands {
npc.setCharacter(character); npc.setCharacter(character);
} }
@Command(
aliases = { "npc" },
usage = "owner [name]",
desc = "Set the owner of an NPC",
modifiers = { "owner" },
min = 2,
max = 2,
permission = "npc.owner")
public void owner(CommandContext args, Player player, NPC npc) {
String name = args.getString(1);
if (npc.getTrait(Owner.class).getOwner().equals(name)) {
Messaging.sendError(player, "'" + name + "' is already the owner of " + npc.getName() + ".");
return;
}
npc.getTrait(Owner.class).setOwner(name);
Messaging.send(player, StringHelper.wrap(name) + " is now the owner of " + StringHelper.wrap(npc.getName())
+ ".");
}
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "spawn [id]", usage = "spawn [id]",
@ -220,7 +239,7 @@ public class NPCCommands {
max = 2, max = 2,
permission = "npc.spawn") permission = "npc.spawn")
@Requirements @Requirements
public void spawnNPC(CommandContext args, Player player, NPC npc) { public void spawn(CommandContext args, Player player, NPC npc) {
NPC respawn = npcManager.getNPC(args.getInteger(1)); NPC respawn = npcManager.getNPC(args.getInteger(1));
if (respawn == null) { if (respawn == null) {
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' exists."); Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' exists.");
@ -250,7 +269,7 @@ public class NPCCommands {
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.tphere") permission = "npc.tphere")
public void teleportNPCToPlayer(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())
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation()); npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
@ -267,7 +286,7 @@ public class NPCCommands {
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.tp") permission = "npc.tp")
public void teleportToNPC(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())
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation()); npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
@ -277,7 +296,7 @@ public class NPCCommands {
@Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = { @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = {
"lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.lookclose") "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.lookclose")
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) { public void lookClose(CommandContext args, Player player, NPC npc) {
LookClose trait = npc.getTrait(LookClose.class); LookClose trait = npc.getTrait(LookClose.class);
trait.toggle(); trait.toggle();
String msg = StringHelper.wrap(npc.getName()) + " will " String msg = StringHelper.wrap(npc.getName()) + " will "

View File

@ -25,6 +25,7 @@ permissions:
citizens.npc.edit.path: true citizens.npc.edit.path: true
citizens.npc.edit.text: true citizens.npc.edit.text: true
citizens.npc.help: true citizens.npc.help: true
citizens.npc.owner: true
citizens.npc.remove: true citizens.npc.remove: true
citizens.npc.remove.all: true citizens.npc.remove.all: true
citizens.npc.rename: true citizens.npc.rename: true