Quest requirements must be loaded as ID, fixes #2082

This commit is contained in:
PikaMug 2023-03-26 22:45:28 -04:00
parent 5f681e7e92
commit 5344c4c6d7
8 changed files with 86 additions and 100 deletions

View File

@ -38,13 +38,13 @@ public interface Requirements {
void setRemoveItems(final List<Boolean> removeItems); void setRemoveItems(final List<Boolean> removeItems);
List<IQuest> getNeededQuests(); List<String> getNeededQuestIds();
void setNeededQuests(final List<IQuest> neededQuests); void setNeededQuestIds(final List<String> neededQuests);
List<IQuest> getBlockQuests(); List<String> getBlockQuestIds();
void setBlockQuests(final List<IQuest> blockQuests); void setBlockQuestIds(final List<String> blockQuests);
List<String> getPermissions(); List<String> getPermissions();

View File

@ -589,11 +589,16 @@ public class Quest implements IQuest {
if (quester.getQuestPoints() < requirements.getQuestPoints()) { if (quester.getQuestPoints() < requirements.getQuestPoints()) {
return false; return false;
} }
if (!quester.getCompletedQuestsTemp().containsAll(requirements.getNeededQuests())) { for (final IQuest q : quester.getCompletedQuestsTemp()) {
return false; if (!requirements.getNeededQuestIds().contains(q.getName())) {
return false;
}
if (!requirements.getBlockQuestIds().contains(q.getName())) {
return false;
}
} }
for (final IQuest q : requirements.getBlockQuests()) { for (final IQuest q : quester.getCurrentQuestsTemp().keySet()) {
if (quester.getCompletedQuestsTemp().contains(q) || quester.getCurrentQuestsTemp().containsKey(q)) { if (!requirements.getBlockQuestIds().contains(q.getName())) {
return false; return false;
} }
} }

View File

@ -1054,18 +1054,21 @@ public class Quester implements IQuester {
finishedRequirements.add(ChatColor.GRAY + "" + requirements.getQuestPoints() + " " + Lang.get("questPoints")); finishedRequirements.add(ChatColor.GRAY + "" + requirements.getQuestPoints() + " " + Lang.get("questPoints"));
} }
} }
for (final IQuest q : requirements.getNeededQuests()) { for (final IQuest q : completedQuests) {
if (q != null) { if (q != null) {
if (getCompletedQuestsTemp().contains(q)) { if (requirements.getNeededQuestIds().contains(q.getId())) {
finishedRequirements.add(ChatColor.GREEN + q.getName()); finishedRequirements.add(ChatColor.GREEN + q.getName());
} else { } else {
unfinishedRequirements.add(ChatColor.GRAY + q.getName()); unfinishedRequirements.add(ChatColor.GRAY + q.getName());
} }
if (requirements.getBlockQuestIds().contains(q.getId())) {
current.add(ChatColor.RED + quest.getName());
}
} }
} }
for (final IQuest q : requirements.getBlockQuests()) { for (final IQuest q : currentQuests.keySet()) {
if (q != null) { if (q != null) {
if (completedQuests.contains(q) || currentQuests.containsKey(q)) { if (requirements.getBlockQuestIds().contains(q.getId())) {
current.add(ChatColor.RED + quest.getName()); current.add(ChatColor.RED + quest.getName());
} }
} }

View File

@ -28,7 +28,6 @@ import me.blackvein.quests.convo.misc.NpcOfferQuestPrompt;
import me.blackvein.quests.dependencies.DenizenTrigger; import me.blackvein.quests.dependencies.DenizenTrigger;
import me.blackvein.quests.dependencies.IDependencies; import me.blackvein.quests.dependencies.IDependencies;
import me.blackvein.quests.entity.BukkitQuestMob; import me.blackvein.quests.entity.BukkitQuestMob;
import me.blackvein.quests.entity.CountableMob;
import me.blackvein.quests.entity.QuestMob; import me.blackvein.quests.entity.QuestMob;
import me.blackvein.quests.events.misc.MiscPostQuestAcceptEvent; import me.blackvein.quests.events.misc.MiscPostQuestAcceptEvent;
import me.blackvein.quests.exceptions.ActionFormatException; import me.blackvein.quests.exceptions.ActionFormatException;
@ -48,11 +47,9 @@ import me.blackvein.quests.listeners.ZnpcsListener;
import me.blackvein.quests.logging.QuestsLog4JFilter; import me.blackvein.quests.logging.QuestsLog4JFilter;
import me.blackvein.quests.module.ICustomObjective; import me.blackvein.quests.module.ICustomObjective;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.quests.BukkitObjective;
import me.blackvein.quests.quests.BukkitQuestFactory; import me.blackvein.quests.quests.BukkitQuestFactory;
import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.IStage; import me.blackvein.quests.quests.IStage;
import me.blackvein.quests.quests.Objective;
import me.blackvein.quests.quests.Options; import me.blackvein.quests.quests.Options;
import me.blackvein.quests.quests.Planner; import me.blackvein.quests.quests.Planner;
import me.blackvein.quests.quests.QuestFactory; import me.blackvein.quests.quests.QuestFactory;
@ -2375,20 +2372,16 @@ public class Quests extends JavaPlugin implements QuestsAPI {
final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quest-blocks"); final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quest-blocks");
boolean failed = false; boolean failed = false;
String failedQuest = "NULL"; String failedQuest = "NULL";
final List<IQuest> temp = new LinkedList<>(); final List<String> temp = new LinkedList<>();
for (final String node : nodes) { for (final String node : nodes) {
boolean done = false; boolean done = false;
for (final String id : questsSection.getKeys(false)) { for (final String id : questsSection.getKeys(false)) {
final String node2 = config.getString("quests." + id + ".name"); if (id.equals(node)) {
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node) if (getQuestByIdTemp(node) != null) {
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) { temp.add(node);
if (getQuestTemp(node) != null) {
temp.add(getQuestTemp(node));
} else if (getQuestByIdTemp(node) != null) {
temp.add(getQuestByIdTemp(node));
} else { } else {
throw new QuestFormatException("Requirement quest-blocks has unknown quest name/id " throw new QuestFormatException("Requirement quest-blocks has unknown quest ID "
+ node + ", place it earlier in file so it loads first", questKey); + node + ", manually update it to a valid ID", questKey);
} }
done = true; done = true;
break; break;
@ -2400,9 +2393,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
break; break;
} }
} }
requires.setBlockQuests(temp); requires.setBlockQuestIds(temp);
if (failed) { if (failed) {
throw new QuestFormatException("Requirement quest-blocks has invalid quest name/id " + failedQuest, throw new QuestFormatException("Requirement quest-blocks has invalid quest ID " + failedQuest,
questKey); questKey);
} }
} else { } else {
@ -2414,20 +2407,16 @@ public class Quests extends JavaPlugin implements QuestsAPI {
final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quests"); final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quests");
boolean failed = false; boolean failed = false;
String failedQuest = "NULL"; String failedQuest = "NULL";
final List<IQuest> temp = new LinkedList<>(); final List<String> temp = new LinkedList<>();
for (final String node : nodes) { for (final String node : nodes) {
boolean done = false; boolean done = false;
for (final String id : questsSection.getKeys(false)) { for (final String id : questsSection.getKeys(false)) {
final String node2 = config.getString("quests." + id + ".name"); if (id.equals(node)) {
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node) if (getQuestByIdTemp(node) != null) {
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) { temp.add(node);
if (getQuestTemp(node) != null) {
temp.add(getQuestTemp(node));
} else if (getQuestByIdTemp(node) != null) {
temp.add(getQuestByIdTemp(node));
} else { } else {
throw new QuestFormatException("Requirement quests has unknown quest name " throw new QuestFormatException("Requirement quests has unknown quest ID "
+ node + ", place it earlier in file so it loads first", questKey); + node + ", manually update it to a valid ID", questKey);
} }
done = true; done = true;
break; break;
@ -2439,9 +2428,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
break; break;
} }
} }
requires.setNeededQuests(temp); requires.setNeededQuestIds(temp);
if (failed) { if (failed) {
throw new QuestFormatException("Requirement quests has invalid quest name/id " throw new QuestFormatException("Requirement quests has invalid quest ID "
+ failedQuest, questKey); + failedQuest, questKey);
} }
} else { } else {

View File

@ -155,17 +155,15 @@ public class QuestCommandHandler {
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass")); + ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
} }
} }
if (!reqs.getMcmmoSkills().isEmpty()) { for (final String skill : reqs.getMcmmoSkills()) {
for (final String skill : reqs.getMcmmoSkills()) { final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests .getMcMMOSkill(skill), player.getName());
.getMcMMOSkill(skill), player.getName()); final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill)); final String skillName = MiscUtil.getCapitalized(skill);
final String skillName = MiscUtil.getCapitalized(skill); if (level >= req) {
if (level >= req) { cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req); } else {
} else { cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
}
} }
} }
if (reqs.getQuestPoints() != 0) { if (reqs.getQuestPoints() != 0) {
@ -191,39 +189,33 @@ public class QuestCommandHandler {
.currencyNameSingular())); .currencyNameSingular()));
} }
} }
if (!reqs.getItems().isEmpty()) { for (final ItemStack is : reqs.getItems()) {
for (final ItemStack is : reqs.getItems()) { if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is)); } else {
} else { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
}
} }
} }
if (!reqs.getNeededQuests().isEmpty()) { for (IQuest quest : quester.getCompletedQuestsTemp()) {
for (final IQuest quest : reqs.getNeededQuests()) { if (reqs.getNeededQuestIds().contains(quest.getId())) {
if (quester.getCompletedQuestsTemp().contains(quest)) { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " " + ChatColor.ITALIC + quest.getName());
+ ChatColor.ITALIC + quest.getName()); } else {
} else { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " "
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " " + ChatColor.ITALIC + quest.getName());
+ ChatColor.ITALIC + quest.getName());
}
} }
} }
if (!reqs.getBlockQuests().isEmpty()) { for (IQuest quest : quester.getCompletedQuestsTemp()) {
for (final IQuest quest : reqs.getBlockQuests()) { if (reqs.getBlockQuestIds().contains(quest.getId())) {
if (quester.getCompletedQuestsTemp().contains(quest)) { String msg = Lang.get("haveCompleted");
String msg = Lang.get("haveCompleted"); msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED);
+ quest.getName() + ChatColor.RED); cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg); } else {
} else { String msg = Lang.get("cannotComplete");
String msg = Lang.get("cannotComplete"); msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GREEN);
+ quest.getName() + ChatColor.GREEN); cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
}
} }
} }
} }

View File

@ -281,8 +281,8 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
final IQuest found = plugin.getQuestTemp(input); final IQuest found = plugin.getQuestTemp(input);
if (found != null) { if (found != null) {
for (final IQuest q : plugin.getLoadedQuests()) { for (final IQuest q : plugin.getLoadedQuests()) {
if (q.getRequirements().getNeededQuests().contains(q) if (q.getRequirements().getNeededQuestIds().contains(q.getId())
|| q.getRequirements().getBlockQuests().contains(q)) { || q.getRequirements().getBlockQuestIds().contains(q.getId())) {
used.add(q.getName()); used.add(q.getName());
} }
} }

View File

@ -53,7 +53,6 @@ import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedListener { public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedListener {
@ -179,13 +178,11 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
context.setSessionData(CK.REQ_ITEMS, requirements.getItems()); context.setSessionData(CK.REQ_ITEMS, requirements.getItems());
context.setSessionData(CK.REQ_ITEMS_REMOVE, requirements.getRemoveItems()); context.setSessionData(CK.REQ_ITEMS_REMOVE, requirements.getRemoveItems());
} }
if (!requirements.getNeededQuests().isEmpty()) { if (!requirements.getNeededQuestIds().isEmpty()) {
final List<String> ids = requirements.getNeededQuests().stream().map(IQuest::getId).collect(Collectors.toList()); context.setSessionData(CK.REQ_QUEST, requirements.getNeededQuestIds());
context.setSessionData(CK.REQ_QUEST, ids);
} }
if (!requirements.getBlockQuests().isEmpty()) { if (!requirements.getBlockQuestIds().isEmpty()) {
final List<String> ids = requirements.getBlockQuests().stream().map(IQuest::getId).collect(Collectors.toList()); context.setSessionData(CK.REQ_QUEST_BLOCK, requirements.getBlockQuestIds());
context.setSessionData(CK.REQ_QUEST_BLOCK, ids);
} }
if (!requirements.getMcmmoSkills().isEmpty()) { if (!requirements.getMcmmoSkills().isEmpty()) {
context.setSessionData(CK.REQ_MCMMO_SKILLS, requirements.getMcmmoAmounts()); context.setSessionData(CK.REQ_MCMMO_SKILLS, requirements.getMcmmoAmounts());

View File

@ -25,8 +25,8 @@ public class BukkitRequirements implements Requirements {
private int exp = 0; private int exp = 0;
private List<ItemStack> items = new LinkedList<>(); private List<ItemStack> items = new LinkedList<>();
private List<Boolean> removeItems = new LinkedList<>(); private List<Boolean> removeItems = new LinkedList<>();
private List<IQuest> neededQuests = new LinkedList<>(); private List<String> neededQuestIds = new LinkedList<>();
private List<IQuest> blockQuests = new LinkedList<>(); private List<String> blockQuestIds = new LinkedList<>();
private List<String> permissions = new LinkedList<>(); private List<String> permissions = new LinkedList<>();
private List<String> mcmmoSkills = new LinkedList<>(); private List<String> mcmmoSkills = new LinkedList<>();
private List<Integer> mcmmoAmounts = new LinkedList<>(); private List<Integer> mcmmoAmounts = new LinkedList<>();
@ -65,17 +65,17 @@ public class BukkitRequirements implements Requirements {
public void setRemoveItems(final List<Boolean> removeItems) { public void setRemoveItems(final List<Boolean> removeItems) {
this.removeItems = removeItems; this.removeItems = removeItems;
} }
public List<IQuest> getNeededQuests() { public List<String> getNeededQuestIds() {
return neededQuests; return neededQuestIds;
} }
public void setNeededQuests(final List<IQuest> neededQuests) { public void setNeededQuestIds(final List<String> neededQuestIds) {
this.neededQuests = neededQuests; this.neededQuestIds = neededQuestIds;
} }
public List<IQuest> getBlockQuests() { public List<String> getBlockQuestIds() {
return blockQuests; return blockQuestIds;
} }
public void setBlockQuests(final List<IQuest> blockQuests) { public void setBlockQuestIds(final List<String> blockQuestIds) {
this.blockQuests = blockQuests; this.blockQuestIds = blockQuestIds;
} }
public List<String> getPermissions() { public List<String> getPermissions() {
return permissions; return permissions;
@ -127,8 +127,8 @@ public class BukkitRequirements implements Requirements {
if (exp != 0) { return true; } if (exp != 0) { return true; }
if (!items.isEmpty()) { return true; } if (!items.isEmpty()) { return true; }
if (!removeItems.isEmpty()) { return true; } if (!removeItems.isEmpty()) { return true; }
if (!neededQuests.isEmpty()) { return true; } if (!neededQuestIds.isEmpty()) { return true; }
if (!blockQuests.isEmpty()) { return true; } if (!blockQuestIds.isEmpty()) { return true; }
if (!permissions.isEmpty()) { return true; } if (!permissions.isEmpty()) { return true; }
if (!mcmmoSkills.isEmpty()) { return true; } if (!mcmmoSkills.isEmpty()) { return true; }
if (!mcmmoAmounts.isEmpty()) { return true; } if (!mcmmoAmounts.isEmpty()) { return true; }