mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-14 22:55:54 +01:00
Ignore locked quests in /quests list if setting enabled, fixes #747
This commit is contained in:
parent
f27897ae14
commit
7187e06f25
@ -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) {
|
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();
|
||||||
|
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"));
|
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
|
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
|
||||||
int fromOrder = (page - 1) * rows;
|
int fromOrder = (page - 1) * rows;
|
||||||
|
|
||||||
List<Quest> subQuests;
|
List<Quest> subQuests;
|
||||||
|
|
||||||
if (quests.size() >= (fromOrder + rows)) {
|
if (quests.size() >= (fromOrder + rows)) {
|
||||||
subQuests = quests.subList((fromOrder), (fromOrder + rows));
|
subQuests = quests.subList((fromOrder), (fromOrder + rows));
|
||||||
} else {
|
} else {
|
||||||
subQuests = quests.subList((fromOrder), quests.size());
|
subQuests = quests.subList((fromOrder), quests.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
fromOrder++;
|
fromOrder++;
|
||||||
|
|
||||||
for (Quest q : subQuests) {
|
for (Quest q : subQuests) {
|
||||||
player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName());
|
player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName());
|
||||||
fromOrder++;
|
fromOrder++;
|
||||||
}
|
}
|
||||||
int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows));
|
int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows));
|
||||||
|
|
||||||
String msg = Lang.get(player, "pageFooter");
|
String msg = Lang.get(player, "pageFooter");
|
||||||
msg = msg.replace("<current>", String.valueOf(page));
|
msg = msg.replace("<current>", String.valueOf(page));
|
||||||
msg = msg.replace("<all>", String.valueOf(numPages));
|
msg = msg.replace("<all>", String.valueOf(numPages));
|
||||||
player.sendMessage(ChatColor.GOLD + msg);
|
player.sendMessage(ChatColor.GOLD + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadQuests() {
|
public void reloadQuests() {
|
||||||
quests.clear();
|
quests.clear();
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user