mirror of https://github.com/PikaMug/Quests.git
Ignore NPCs without plugin affiliation, fixes #1964
This commit is contained in:
parent
11612439f9
commit
1eb79a6d14
|
@ -151,6 +151,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
private final Collection<IQuest> quests = new ConcurrentSkipListSet<>();
|
||||
private Collection<IAction> actions = new ConcurrentSkipListSet<>();
|
||||
private Collection<ICondition> conditions = new ConcurrentSkipListSet<>();
|
||||
private Collection<UUID> questNpcUuids = new ConcurrentSkipListSet<>();
|
||||
private TabExecutor cmdExecutor;
|
||||
private ConversationFactory conversationFactory;
|
||||
private ConversationFactory npcConversationFactory;
|
||||
|
@ -534,6 +535,24 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
this.questers = new ConcurrentSkipListSet<>(questers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get every NPC UUID which sees use a quest giver, talk target, or kill target
|
||||
*
|
||||
* @return a collection of all UUIDs
|
||||
*/
|
||||
public Collection<UUID> getQuestNpcUuids() {
|
||||
return questNpcUuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set every NPC UUID which sees use a quest giver, talk target, or kill target
|
||||
*
|
||||
* @param questNpcUuids a collection of UUIDs
|
||||
*/
|
||||
public void setQuestNpcUuids(final Collection<UUID> questNpcUuids) {
|
||||
this.questNpcUuids = new ConcurrentSkipListSet<>(questNpcUuids);
|
||||
}
|
||||
|
||||
public CommandExecutor getCommandExecutor() {
|
||||
return cmdExecutor;
|
||||
}
|
||||
|
@ -1826,6 +1845,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
+ ".npc-giver-uuid")));
|
||||
if (CitizensAPI.getNPCRegistry().getByUniqueId(uuid) != null) {
|
||||
quest.setNpcStart(CitizensAPI.getNPCRegistry().getByUniqueId(uuid));
|
||||
questNpcUuids.add(uuid);
|
||||
} else {
|
||||
throw new QuestFormatException("npc-giver-uuid has invalid NPC UUID " + uuid, questKey);
|
||||
}
|
||||
|
@ -1833,7 +1853,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
// Legacy
|
||||
final int id = config.getInt("quests." + questKey + ".npc-giver-id");
|
||||
if (CitizensAPI.getNPCRegistry().getById(id) != null) {
|
||||
quest.setNpcStart(CitizensAPI.getNPCRegistry().getById(id));
|
||||
final NPC npc = CitizensAPI.getNPCRegistry().getById(id);
|
||||
quest.setNpcStart(npc);
|
||||
questNpcUuids.add(npc.getUniqueId());
|
||||
} else {
|
||||
throw new QuestFormatException("npc-giver-id has invalid NPC ID " + id, questKey);
|
||||
}
|
||||
|
@ -2909,9 +2931,10 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
for (final String s : npcUuidsToTalkTo) {
|
||||
final UUID uuid = UUID.fromString(s);
|
||||
if (getDependencies().getCitizens() != null) {
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(uuid);
|
||||
final NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(uuid);
|
||||
if (npc != null) {
|
||||
oStage.addNpcToInteract(uuid);
|
||||
questNpcUuids.add(uuid);
|
||||
} else {
|
||||
throw new StageFormatException("npc-uuids-to-talk-to has invalid NPC UUID of "
|
||||
+ s, quest, stageNum);
|
||||
|
@ -2936,6 +2959,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
if (npc != null) {
|
||||
final UUID npcUuid = npc.getUniqueId();
|
||||
oStage.addNpcToInteract(npcUuid);
|
||||
questNpcUuids.add(npcUuid);
|
||||
} else {
|
||||
throw new StageFormatException("npc-ids-to-talk-to has invalid NPC ID of " + i, quest,
|
||||
stageNum);
|
||||
|
@ -3061,6 +3085,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
if (npcAmountsToKill.get(npcUuidsToKill.indexOf(s)) > 0) {
|
||||
oStage.addNpcToKill(npcUuid);
|
||||
oStage.addNpcNumToKill(npcAmountsToKill.get(npcUuidsToKill.indexOf(s)));
|
||||
questNpcUuids.add(npcUuid);
|
||||
} else {
|
||||
throw new StageFormatException("npc-kill-amounts is not a positive number",
|
||||
quest, stageNum);
|
||||
|
@ -3096,6 +3121,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
final UUID npcUuid = npc.getUniqueId();
|
||||
oStage.addNpcToKill(npcUuid);
|
||||
oStage.addNpcNumToKill(npcAmountsToKill.get(npcIdsToKill.indexOf(i)));
|
||||
questNpcUuids.add(npcUuid);
|
||||
} else {
|
||||
throw new StageFormatException("npc-kill-amounts is not a positive number",
|
||||
quest, stageNum);
|
||||
|
|
|
@ -205,61 +205,62 @@ public class NpcListener implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!hasObjective) {
|
||||
boolean hasAtLeastOneGUI = false;
|
||||
final LinkedList<IQuest> npcQuests = new LinkedList<>();
|
||||
for (final IQuest q : plugin.getLoadedQuests()) {
|
||||
if (quester.getCurrentQuestsTemp().containsKey(q)) {
|
||||
continue;
|
||||
}
|
||||
if (q.getNpcStart() != null && q.getNpcStart().getId() == evt.getNPC().getId()) {
|
||||
if (plugin.getSettings().canIgnoreLockedQuests()
|
||||
&& (!quester.getCompletedQuestsTemp().contains(q)
|
||||
|| q.getPlanner().getCooldown() > -1)) {
|
||||
if (q.testRequirements(quester)) {
|
||||
npcQuests.add(q);
|
||||
if (q.getGUIDisplay() != null) {
|
||||
hasAtLeastOneGUI = true;
|
||||
}
|
||||
}
|
||||
} else if (!quester.getCompletedQuestsTemp().contains(q) || q.getPlanner().getCooldown() > -1) {
|
||||
if (hasObjective || !plugin.getQuestNpcUuids().contains(evt.getNPC().getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
boolean hasAtLeastOneGUI = false;
|
||||
final LinkedList<IQuest> npcQuests = new LinkedList<>();
|
||||
for (final IQuest q : plugin.getLoadedQuests()) {
|
||||
if (quester.getCurrentQuestsTemp().containsKey(q)) {
|
||||
continue;
|
||||
}
|
||||
if (q.getNpcStart() != null && q.getNpcStart().getId() == evt.getNPC().getId()) {
|
||||
if (plugin.getSettings().canIgnoreLockedQuests()
|
||||
&& (!quester.getCompletedQuestsTemp().contains(q)
|
||||
|| q.getPlanner().getCooldown() > -1)) {
|
||||
if (q.testRequirements(quester)) {
|
||||
npcQuests.add(q);
|
||||
if (q.getGUIDisplay() != null) {
|
||||
hasAtLeastOneGUI = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (npcQuests.size() == 1) {
|
||||
final IQuest q = npcQuests.get(0);
|
||||
if (quester.canAcceptOffer(q, true)) {
|
||||
quester.setQuestIdToTake(q.getId());
|
||||
if (!plugin.getSettings().canAskConfirmation()) {
|
||||
quester.takeQuest(q, false);
|
||||
} else {
|
||||
if (q.getGUIDisplay() != null) {
|
||||
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests);
|
||||
} else {
|
||||
for (final String msg : extracted(quester).split("<br>")) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
plugin.getConversationFactory().buildConversation(player).begin();
|
||||
}
|
||||
} else if (!quester.getCompletedQuestsTemp().contains(q) || q.getPlanner().getCooldown() > -1) {
|
||||
npcQuests.add(q);
|
||||
if (q.getGUIDisplay() != null) {
|
||||
hasAtLeastOneGUI = true;
|
||||
}
|
||||
}
|
||||
} else if (npcQuests.size() > 1) {
|
||||
if (hasAtLeastOneGUI) {
|
||||
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests);
|
||||
} else {
|
||||
final Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
|
||||
c.getContext().setSessionData("npcQuests", npcQuests);
|
||||
c.getContext().setSessionData("npc", evt.getNPC().getName());
|
||||
c.begin();
|
||||
}
|
||||
} else {
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "noMoreQuest"));
|
||||
}
|
||||
}
|
||||
if (npcQuests.size() == 1) {
|
||||
final IQuest q = npcQuests.get(0);
|
||||
if (quester.canAcceptOffer(q, true)) {
|
||||
quester.setQuestIdToTake(q.getId());
|
||||
if (!plugin.getSettings().canAskConfirmation()) {
|
||||
quester.takeQuest(q, false);
|
||||
} else {
|
||||
if (q.getGUIDisplay() != null) {
|
||||
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests);
|
||||
} else {
|
||||
for (final String msg : extracted(quester).split("<br>")) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
plugin.getConversationFactory().buildConversation(player).begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (npcQuests.size() > 1) {
|
||||
if (hasAtLeastOneGUI) {
|
||||
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests);
|
||||
} else {
|
||||
final Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
|
||||
c.getContext().setSessionData("npcQuests", npcQuests);
|
||||
c.getContext().setSessionData("npc", evt.getNPC().getName());
|
||||
c.begin();
|
||||
}
|
||||
} else {
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "noMoreQuest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue