Potential fix for #930

This commit is contained in:
PikaMug 2019-09-06 00:54:01 -04:00
parent 50a73bb463
commit 5defc587a3

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.Conversation;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -167,6 +168,7 @@ public class NpcListener implements Listener {
} }
} }
if (!hasObjective) { if (!hasObjective) {
boolean hasAtLeastOneGUI = false;
LinkedList<Quest> npcQuests = new LinkedList<Quest>(); LinkedList<Quest> npcQuests = new LinkedList<Quest>();
for (Quest q : plugin.getQuests()) { for (Quest q : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(q)) if (quester.getCurrentQuests().containsKey(q))
@ -175,14 +177,27 @@ public class NpcListener implements Listener {
if (plugin.getSettings().canIgnoreLockedQuests() && (quester.getCompletedQuests().contains(q.getName()) == false || q.getPlanner().getCooldown() > -1)) { if (plugin.getSettings().canIgnoreLockedQuests() && (quester.getCompletedQuests().contains(q.getName()) == false || q.getPlanner().getCooldown() > -1)) {
if (q.testRequirements(quester)) { if (q.testRequirements(quester)) {
npcQuests.add(q); npcQuests.add(q);
if (q.getGUIDisplay() != null) {
hasAtLeastOneGUI = true;
}
} }
} else if (quester.getCompletedQuests().contains(q.getName()) == false || q.getPlanner().getCooldown() > -1) { } else if (quester.getCompletedQuests().contains(q.getName()) == false || q.getPlanner().getCooldown() > -1) {
npcQuests.add(q); npcQuests.add(q);
if (q.getGUIDisplay() != null) {
hasAtLeastOneGUI = true;
}
} }
} }
} }
if (npcQuests.isEmpty() == false && npcQuests.size() >= 1) { if (npcQuests.isEmpty() == false && npcQuests.size() >= 1) {
if (hasAtLeastOneGUI) {
quester.showGUIDisplay(evt.getNPC(), npcQuests); 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; return;
} else if (npcQuests.size() == 1) { } else if (npcQuests.size() == 1) {
// TODO can this block even be reached? // TODO can this block even be reached?
@ -197,18 +212,18 @@ public class NpcListener implements Listener {
plugin.getNpcConversationFactory().buildConversation(player).begin(); plugin.getNpcConversationFactory().buildConversation(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.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.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) { } else 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(player, "questTooEarly"); String early = Lang.get(player, "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(player, "questAlreadyCompleted"); String completed = Lang.get(player, "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());
@ -220,7 +235,7 @@ public class NpcListener implements Listener {
} }
} 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.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 (npcQuests.isEmpty()) { } else if (npcQuests.isEmpty()) {