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

@ -1235,36 +1235,84 @@ 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 player = quester.getPlayer();
if (getSettings().canIgnoreLockedQuests()) {
LinkedList<Quest> available = new LinkedList<Quest>();
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 {
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
int fromOrder = (page - 1) * rows;
List<Quest> 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("<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);
}
}
}
public void reloadQuests() {
quests.clear();

View File

@ -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) {