diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index 2b27b3478..d89ad0d4e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -328,7 +328,7 @@ public enum C { HELP_INFO("&6You need to specify a help category"), HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"), - HELP_HEADER("&6Help for Plots"), + HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"), /* * Direction */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 1d58eacc4..bf8f0aa27 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -87,7 +87,13 @@ public class MainCommand implements CommandExecutor, TabCompleter { return true; } StringBuilder help = new StringBuilder(); - for (String string : helpMenu(player, cato)) { + int page = 0; + try { + page = Integer.parseInt(args[2]); + --page; + if(page < 0) page = 0; + } catch(Exception e) {} + for (String string : helpMenu(player, cato, page)) { help.append(string).append("\n"); } PlayerFunctions.sendMessage(player, help.toString()); @@ -123,23 +129,71 @@ public class MainCommand implements CommandExecutor, TabCompleter { return false; } - public static ArrayList helpMenu(Player player, final SubCommand.CommandCategory category) { - ArrayList help = new ArrayList() { - { - add(t(C.HELP_HEADER.s())); - add(t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString()))); - } - }; - for (SubCommand cmd : subCommands) { - if (cmd.permission.hasPermission(player) && (cmd.category == category)) { - String s = t(C.HELP_PAGE.s()); - s = s.replaceAll("%alias%", cmd.alias); - s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage); - s = s.replaceAll("%cmd%", cmd.cmd); - s = s.replaceAll("%desc%", cmd.description); - help.add(s); - } - } + + public static List getCommands(SubCommand.CommandCategory category, Player player) { + List cmds = new ArrayList<>(); + for(SubCommand c : subCommands) + if(c.category == category && c.permission.hasPermission(player)) + cmds.add(c); + return cmds; + } + + /* + // Current page + int page = 0; + + //is a page specified? else use 0 + if(args.length > 1) { + try { + page = Integer.parseInt(args[1]); + } catch(Exception e) { + page = 0; + } + } + + //Get the total pages + int totalPages = ((int) Math.ceil(12 * (PlotMain.getPlotsSorted().size()) / 100)); + + if(page > totalPages) + page = totalPages; + + //Only display 12! + int max = (page * 12) + 12; + + if(max > PlotMain.getPlotsSorted().size()) + max = PlotMain.getPlotsSorted().size(); + + StringBuilder string = new StringBuilder(); + + string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all") + "\n"); + Plot p; + + //This might work xD + for (int x = (page * 12); x < max; x++) { + */ + public static ArrayList helpMenu(Player player, final SubCommand.CommandCategory category, int page) { + List commands = getCommands(category, player); + final int totalPages = ((int) Math.ceil(12 * (commands.size()) / 100)); + if(page > totalPages) + page = totalPages; + int max = (page * 12) + 12; + if(max > commands.size()) + max = commands.size(); + ArrayList help = new ArrayList<>( + Arrays.asList( + t(C.HELP_HEADER.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "")), + t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString())) + )); + SubCommand cmd; + for(int x = (page * 12); x < max; x++) { + cmd = subCommands.get(x); + String s = t(C.HELP_PAGE.s()); + s = s.replaceAll("%alias%", cmd.alias); + s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage); + s = s.replaceAll("%cmd%", cmd.cmd); + s = s.replaceAll("%desc%", cmd.description); + help.add(s); + } if (help.size() < 2) { help.add(t(C.NO_COMMANDS.s())); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 328e45fe5..0055491b9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -78,6 +78,8 @@ public class list extends SubCommand { if(args.length > 1) { try { page = Integer.parseInt(args[1]); + --page; + if(page < 0) page = 0; } catch(Exception e) { page = 0; }