diff --git a/src/main/java/net/citizensnpcs/command/command/HelpCommands.java b/src/main/java/net/citizensnpcs/command/command/HelpCommands.java index 69542df9b..eed6fc53e 100644 --- a/src/main/java/net/citizensnpcs/command/command/HelpCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/HelpCommands.java @@ -14,13 +14,10 @@ import net.citizensnpcs.command.CommandContext; import net.citizensnpcs.command.CommandManager; import net.citizensnpcs.command.Requirements; import net.citizensnpcs.command.exception.CommandException; -import net.citizensnpcs.util.Messaging; -import net.citizensnpcs.util.StringHelper; +import net.citizensnpcs.util.Paginator; @Requirements public class HelpCommands { - private static final int LINES_PER_PAGE = 9; - private final CommandManager cmdManager; public HelpCommands(Citizens plugin) { @@ -38,7 +35,11 @@ public class HelpCommands { @Requirements public void citizensHelp(CommandContext args, Player player, NPC npc) throws CommandException { int page = args.argsLength() == 2 ? args.getInteger(1) : 1; - if (!sendPage(player, args.getCommand(), page)) + Paginator paginator = new Paginator(); + for (String line : getLines(player, "citizens")) + paginator.addLine(line); + paginator.setHeaderText("Citizens Help"); + if (!paginator.sendPage(player, page)) throw new CommandException("The page '" + page + "' does not exist."); } @@ -53,30 +54,14 @@ public class HelpCommands { @Requirements public void npcHelp(CommandContext args, Player player, NPC npc) throws CommandException { int page = args.argsLength() == 2 ? args.getInteger(1) : 1; - if (!sendPage(player, args.getCommand(), page)) + Paginator paginator = new Paginator(); + for (String line : getLines(player, "npc")) + paginator.addLine(line); + paginator.setHeaderText("NPC Help"); + if (!paginator.sendPage(player, page)) throw new CommandException("The page '" + page + "' does not exist."); } - private boolean sendPage(Player player, String baseCommand, int page) { - List lines = getLines(player, baseCommand); - int pages = (int) ((lines.size() / LINES_PER_PAGE == 0) ? 1 : Math.ceil((double) lines.size() / LINES_PER_PAGE)); - if (page < 0 || page > pages) - return false; - - int startIndex = LINES_PER_PAGE * page - LINES_PER_PAGE; - int endIndex = page * LINES_PER_PAGE; - - Messaging.send(player, StringHelper.wrapHeader("" - + (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand.toLowerCase())) - + " Help " + page + "/" + pages)); - - if (lines.size() < endIndex) - endIndex = lines.size(); - for (String line : lines.subList(startIndex, endIndex)) - Messaging.send(player, line); - return true; - } - private List getLines(Player player, String baseCommand) { // Ensures that commands with multiple modifiers are only added once Set cmds = new HashSet(); diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 0d0dfe64b..cf10a825d 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -45,7 +45,7 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "create [name] --type (type) --char (character)", + usage = "create [name] (--type (type) --char (char))", desc = "Create a new NPC", modifiers = { "create" }, min = 2, @@ -282,4 +282,17 @@ public class NPCCommands { + (trait.shouldLookClose() ? "now rotate" : "no longer rotate"); Messaging.send(player, msg += " when a player is nearby."); } + + @Command( + aliases = { "npc" }, + usage = "list (--type (type) --char (char)", + desc = "List NPCs", + modifiers = { "list" }, + min = 2, + max = 5, + permission = "npc.list") + @Requirements + public void list(CommandContext args, Player player, NPC npc) { + + } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/util/Paginator.java b/src/main/java/net/citizensnpcs/util/Paginator.java new file mode 100644 index 000000000..09c349144 --- /dev/null +++ b/src/main/java/net/citizensnpcs/util/Paginator.java @@ -0,0 +1,38 @@ +package net.citizensnpcs.util; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +public class Paginator { + private static final int LINES_PER_PAGE = 9; + + private final List lines = new ArrayList(); + private String header; + + public void addLine(String line) { + lines.add(line); + } + + public void setHeaderText(String header) { + this.header = header; + } + + public boolean sendPage(Player player, int page) { + int pages = (int) ((lines.size() / LINES_PER_PAGE == 0) ? 1 : Math.ceil((double) lines.size() / LINES_PER_PAGE)); + if (page < 0 || page > pages) + return false; + + int startIndex = LINES_PER_PAGE * page - LINES_PER_PAGE; + int endIndex = page * LINES_PER_PAGE; + + Messaging.send(player, StringHelper.wrapHeader("" + header + " " + page + "/" + pages)); + + if (lines.size() < endIndex) + endIndex = lines.size(); + for (String line : lines.subList(startIndex, endIndex)) + Messaging.send(player, line); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/util/StringHelper.java b/src/main/java/net/citizensnpcs/util/StringHelper.java index 58db916f4..92c802f44 100644 --- a/src/main/java/net/citizensnpcs/util/StringHelper.java +++ b/src/main/java/net/citizensnpcs/util/StringHelper.java @@ -71,11 +71,11 @@ public class StringHelper { public static String capitalize(Object string) { String capitalize = string.toString(); - return capitalize.replaceFirst(String.valueOf(capitalize.charAt(0)), - String.valueOf(Character.toUpperCase(capitalize.charAt(0)))); + return capitalize.replaceFirst(String.valueOf(capitalize.charAt(0)), String.valueOf(Character + .toUpperCase(capitalize.charAt(0)))); } public static String wrapHeader(Object string) { - return ChatColor.GREEN + "=====[ " + string.toString() + ChatColor.GREEN + " ]====="; + return "=====[ " + string.toString() + " ]====="; } } \ No newline at end of file