Skip list menu if NPC has only one quest

This commit is contained in:
PikaMug 2019-09-25 01:09:02 -04:00
parent dfedd0f885
commit fcf24a51cb
2 changed files with 29 additions and 22 deletions

View File

@ -18,6 +18,7 @@ import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation; import org.bukkit.conversations.Conversation;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -189,18 +190,7 @@ public class NpcListener implements Listener {
} }
} }
} }
if (npcQuests.isEmpty() == false && npcQuests.size() >= 1) { if (npcQuests.isEmpty() == false && npcQuests.size() == 1) {
if (hasAtLeastOneGUI) {
quester.showGUIDisplay(evt.getNPC(), npcQuests);
} else {
Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
c.getContext().setSessionData("quests", npcQuests);
c.getContext().setSessionData("npc", evt.getNPC().getName());
c.begin();
}
return;
} else if (npcQuests.size() == 1) {
// TODO can this block even be reached?
Quest q = npcQuests.get(0); Quest q = npcQuests.get(0);
if (!quester.getCompletedQuests().contains(q.getName())) { if (!quester.getCompletedQuests().contains(q.getName())) {
if (quester.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) { if (quester.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) {
@ -209,7 +199,11 @@ public class NpcListener implements Listener {
for (String msg : s.split("<br>")) { for (String msg : s.split("<br>")) {
player.sendMessage(msg); player.sendMessage(msg);
} }
plugin.getNpcConversationFactory().buildConversation(player).begin(); if (!plugin.getSettings().canAskConfirmation()) {
plugin.getQuester(player.getUniqueId()).takeQuest(plugin.getQuest(plugin.getQuester(player.getUniqueId()).getQuestToTake()), false);
} else {
plugin.getConversationFactory().buildConversation((Conversable) player).begin();
}
} else if (quester.getCurrentQuests().containsKey(q) == false) { } else if (quester.getCurrentQuests().containsKey(q) == false) {
String msg = Lang.get(player, "questMaxAllowed"); String msg = Lang.get(player, "questMaxAllowed");
msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests())); msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests()));
@ -231,13 +225,27 @@ public class NpcListener implements Listener {
for (String msg : s.split("<br>")) { for (String msg : s.split("<br>")) {
player.sendMessage(msg); player.sendMessage(msg);
} }
plugin.getConversationFactory().buildConversation(player).begin(); if (!plugin.getSettings().canAskConfirmation()) {
plugin.getQuester(player.getUniqueId()).takeQuest(plugin.getQuest(plugin.getQuester(player.getUniqueId()).getQuestToTake()), false);
} else {
plugin.getConversationFactory().buildConversation((Conversable) player).begin();
}
} }
} else if (quester.getCurrentQuests().containsKey(q) == false) { } else if (quester.getCurrentQuests().containsKey(q) == false) {
String msg = Lang.get(player, "questMaxAllowed"); String msg = Lang.get(player, "questMaxAllowed");
msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests())); msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests()));
player.sendMessage(ChatColor.YELLOW + msg); player.sendMessage(ChatColor.YELLOW + msg);
} }
} else if (npcQuests.isEmpty() == false && npcQuests.size() > 1) {
if (hasAtLeastOneGUI) {
quester.showGUIDisplay(evt.getNPC(), npcQuests);
} else {
Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
c.getContext().setSessionData("quests", npcQuests);
c.getContext().setSessionData("npc", evt.getNPC().getName());
c.begin();
}
return;
} else if (npcQuests.isEmpty()) { } else if (npcQuests.isEmpty()) {
evt.getClicker().sendMessage(ChatColor.YELLOW + Lang.get(player, "noMoreQuest")); evt.getClicker().sendMessage(ChatColor.YELLOW + Lang.get(player, "noMoreQuest"));
} }

View File

@ -44,8 +44,7 @@ public class QuestAcceptPrompt extends StringPrompt {
quests = (LinkedList<Quest>) cc.getSessionData("quests"); quests = (LinkedList<Quest>) cc.getSessionData("quests");
quester = plugin.getQuester(((Player) cc.getForWhom()).getUniqueId()); quester = plugin.getQuester(((Player) cc.getForWhom()).getUniqueId());
String npc = (String) cc.getSessionData("npc"); String npc = (String) cc.getSessionData("npc");
String text = Lang.get("questNPCListTitle"); String text = Lang.get("questNPCListTitle").replace("<npc>", npc);
text = text.replaceAll("<npc>", npc);
String menu = text + "\n"; String menu = text + "\n";
for (int i = 1; i <= quests.size(); i++) { for (int i = 1; i <= quests.size(); i++) {
Quest quest = quests.get(i - 1); Quest quest = quests.get(i - 1);
@ -118,19 +117,19 @@ public class QuestAcceptPrompt extends StringPrompt {
} }
} else if (quester.getCurrentQuests().containsKey(q) == false) { } else if (quester.getCurrentQuests().containsKey(q) == false) {
String msg = Lang.get("questMaxAllowed"); String msg = Lang.get("questMaxAllowed");
msg = msg.replaceAll("<number>", String.valueOf(plugin.getSettings().getMaxQuests())); msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests()));
player.sendMessage(ChatColor.YELLOW + msg); player.sendMessage(ChatColor.YELLOW + msg);
} }
} else if (quester.getCompletedQuests().contains(q.getName())) { } else if (quester.getCompletedQuests().contains(q.getName())) {
if (quester.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) { if (quester.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) {
if (quester.getCooldownDifference(q) > 0) { if (quester.getCooldownDifference(q) > 0) {
String early = Lang.get("questTooEarly"); String early = Lang.get("questTooEarly");
early = early.replaceAll("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW); early = early.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
early = early.replaceAll("<time>", ChatColor.DARK_PURPLE + Quests.getTime(quester.getCooldownDifference(q)) + ChatColor.YELLOW); early = early.replace("<time>", ChatColor.DARK_PURPLE + Quests.getTime(quester.getCooldownDifference(q)) + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early); player.sendMessage(ChatColor.YELLOW + early);
} else if (q.getPlanner().getCooldown() < 0) { } else if (q.getPlanner().getCooldown() < 0) {
String completed = Lang.get("questAlreadyCompleted"); String completed = Lang.get("questAlreadyCompleted");
completed = completed.replaceAll("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW); completed = completed.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + completed); player.sendMessage(ChatColor.YELLOW + completed);
} else { } else {
quester.setQuestToTake(q.getName()); quester.setQuestToTake(q.getName());
@ -146,7 +145,7 @@ public class QuestAcceptPrompt extends StringPrompt {
} }
} else if (quester.getCurrentQuests().containsKey(q) == false) { } else if (quester.getCurrentQuests().containsKey(q) == false) {
String msg = Lang.get("questMaxAllowed"); String msg = Lang.get("questMaxAllowed");
msg = msg.replaceAll("<number>", String.valueOf(plugin.getSettings().getMaxQuests())); msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests()));
player.sendMessage(ChatColor.YELLOW + msg); player.sendMessage(ChatColor.YELLOW + msg);
} }
} }