mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-28 21:56:28 +01:00
Ignore locked quests in /quests list if setting enabled, fixes #747
This commit is contained in:
parent
f27897ae14
commit
7187e06f25
@ -1235,34 +1235,82 @@ 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<Quest> subQuests;
|
||||
|
||||
if (quests.size() >= (fromOrder + rows)) {
|
||||
subQuests = quests.subList((fromOrder), (fromOrder + rows));
|
||||
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 {
|
||||
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<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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user