diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index 84a0a9886..6b8c7c0d5 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -1234,35 +1234,83 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } } - + + /** + * Show the player a list of their quests + * + * @deprecated Use #listQuests(Quester) + * @param player Player to show the list + * @param page Page to display, with 7 quests per page + */ public void listQuests(Player player, int page) { + listQuests(getQuester(player.getUniqueId()), page); + } + + /** + * Show the player a list of their quests + * + * @param player Player to show the list + * @param page Page to display, with 7 quests per page + */ + public void listQuests(Quester quester, int page) { + // Although we could copy the quests list to a new object, we instead opt to + // duplicate code to improve efficiency if ignore-locked-quests is set to 'false' int rows = 7; - if ((quests.size() + rows) < ((page * rows)) || quests.size() == 0) { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); - } else { - player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); - int fromOrder = (page - 1) * rows; - - List subQuests; - - if (quests.size() >= (fromOrder + rows)) { - subQuests = quests.subList((fromOrder), (fromOrder + rows)); + Player player = quester.getPlayer(); + if (getSettings().canIgnoreLockedQuests()) { + LinkedList available = new LinkedList(); + for (Quest q : quests) { + if (quester.getCompletedQuests().contains(q.getName()) == false) { + if (q.testRequirements(player)) { + available.add(q); + } + } + } + if ((available.size() + rows) <= ((page * rows)) || available.size() == 0) { + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); } else { - subQuests = quests.subList((fromOrder), quests.size()); - } - - fromOrder++; - - for (Quest q : subQuests) { - player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); + player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); + int fromOrder = (page - 1) * rows; + List subQuests; + if (available.size() >= (fromOrder + rows)) { + subQuests = available.subList((fromOrder), (fromOrder + rows)); + } else { + subQuests = available.subList((fromOrder), available.size()); + } fromOrder++; + for (Quest q : subQuests) { + player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); + fromOrder++; + } + int numPages = (int) Math.ceil(((double) available.size()) / ((double) rows)); + String msg = Lang.get(player, "pageFooter"); + msg = msg.replace("", String.valueOf(page)); + msg = msg.replace("", String.valueOf(numPages)); + player.sendMessage(ChatColor.GOLD + msg); + } + } else { + if ((quests.size() + rows) <= ((page * rows)) || quests.size() == 0) { + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); + } else { + player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); + int fromOrder = (page - 1) * rows; + List subQuests; + if (quests.size() >= (fromOrder + rows)) { + subQuests = quests.subList((fromOrder), (fromOrder + rows)); + } else { + subQuests = quests.subList((fromOrder), quests.size()); + } + fromOrder++; + for (Quest q : subQuests) { + player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); + fromOrder++; + } + int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows)); + String msg = Lang.get(player, "pageFooter"); + msg = msg.replace("", String.valueOf(page)); + msg = msg.replace("", String.valueOf(numPages)); + player.sendMessage(ChatColor.GOLD + msg); } - int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows)); - - String msg = Lang.get(player, "pageFooter"); - msg = msg.replace("", String.valueOf(page)); - msg = msg.replace("", String.valueOf(numPages)); - player.sendMessage(ChatColor.GOLD + msg); } } diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 1eb487a2b..a2e7264f0 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -755,6 +755,7 @@ public class CmdExecutor implements CommandExecutor { } } + @SuppressWarnings("deprecation") private void questsList(final CommandSender cs, String[] args) { if (((Player) cs).hasPermission("quests.list")) { if (args.length == 1) {