Ignore locked quests in /quests list if setting enabled, fixes #747

This commit is contained in:
PikaMug 2019-07-10 01:12:51 -04:00
parent f27897ae14
commit 7187e06f25
2 changed files with 73 additions and 24 deletions

View File

@ -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) { 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; int rows = 7;
if ((quests.size() + rows) < ((page * rows)) || quests.size() == 0) { Player player = quester.getPlayer();
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); if (getSettings().canIgnoreLockedQuests()) {
} else { LinkedList<Quest> available = new LinkedList<Quest>();
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); for (Quest q : quests) {
int fromOrder = (page - 1) * rows; if (quester.getCompletedQuests().contains(q.getName()) == false) {
if (q.testRequirements(player)) {
List<Quest> subQuests; available.add(q);
}
if (quests.size() >= (fromOrder + rows)) { }
subQuests = quests.subList((fromOrder), (fromOrder + rows)); }
if ((available.size() + rows) <= ((page * rows)) || available.size() == 0) {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
} else { } else {
subQuests = quests.subList((fromOrder), quests.size()); player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
} int fromOrder = (page - 1) * rows;
List<Quest> subQuests;
fromOrder++; if (available.size() >= (fromOrder + rows)) {
subQuests = available.subList((fromOrder), (fromOrder + rows));
for (Quest q : subQuests) { } else {
player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); subQuests = available.subList((fromOrder), available.size());
}
fromOrder++; 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("<current>", String.valueOf(page));
msg = msg.replace("<all>", 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<Quest> 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("<current>", String.valueOf(page));
msg = msg.replace("<all>", 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("<current>", String.valueOf(page));
msg = msg.replace("<all>", String.valueOf(numPages));
player.sendMessage(ChatColor.GOLD + msg);
} }
} }

View File

@ -755,6 +755,7 @@ public class CmdExecutor implements CommandExecutor {
} }
} }
@SuppressWarnings("deprecation")
private void questsList(final CommandSender cs, String[] args) { private void questsList(final CommandSender cs, String[] args) {
if (((Player) cs).hasPermission("quests.list")) { if (((Player) cs).hasPermission("quests.list")) {
if (args.length == 1) { if (args.length == 1) {