mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 02:25:42 +01:00
Quest requirements must be loaded as ID, fixes #2082
This commit is contained in:
parent
5f681e7e92
commit
5344c4c6d7
@ -38,13 +38,13 @@ public interface Requirements {
|
||||
|
||||
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();
|
||||
|
||||
|
@ -589,11 +589,16 @@ public class Quest implements IQuest {
|
||||
if (quester.getQuestPoints() < requirements.getQuestPoints()) {
|
||||
return false;
|
||||
}
|
||||
if (!quester.getCompletedQuestsTemp().containsAll(requirements.getNeededQuests())) {
|
||||
return false;
|
||||
for (final IQuest q : quester.getCompletedQuestsTemp()) {
|
||||
if (!requirements.getNeededQuestIds().contains(q.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (!requirements.getBlockQuestIds().contains(q.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (final IQuest q : requirements.getBlockQuests()) {
|
||||
if (quester.getCompletedQuestsTemp().contains(q) || quester.getCurrentQuestsTemp().containsKey(q)) {
|
||||
for (final IQuest q : quester.getCurrentQuestsTemp().keySet()) {
|
||||
if (!requirements.getBlockQuestIds().contains(q.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1054,18 +1054,21 @@ public class Quester implements IQuester {
|
||||
finishedRequirements.add(ChatColor.GRAY + "" + requirements.getQuestPoints() + " " + Lang.get("questPoints"));
|
||||
}
|
||||
}
|
||||
for (final IQuest q : requirements.getNeededQuests()) {
|
||||
for (final IQuest q : completedQuests) {
|
||||
if (q != null) {
|
||||
if (getCompletedQuestsTemp().contains(q)) {
|
||||
if (requirements.getNeededQuestIds().contains(q.getId())) {
|
||||
finishedRequirements.add(ChatColor.GREEN + q.getName());
|
||||
} else {
|
||||
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 (completedQuests.contains(q) || currentQuests.containsKey(q)) {
|
||||
if (requirements.getBlockQuestIds().contains(q.getId())) {
|
||||
current.add(ChatColor.RED + quest.getName());
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import me.blackvein.quests.convo.misc.NpcOfferQuestPrompt;
|
||||
import me.blackvein.quests.dependencies.DenizenTrigger;
|
||||
import me.blackvein.quests.dependencies.IDependencies;
|
||||
import me.blackvein.quests.entity.BukkitQuestMob;
|
||||
import me.blackvein.quests.entity.CountableMob;
|
||||
import me.blackvein.quests.entity.QuestMob;
|
||||
import me.blackvein.quests.events.misc.MiscPostQuestAcceptEvent;
|
||||
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.module.ICustomObjective;
|
||||
import me.blackvein.quests.player.IQuester;
|
||||
import me.blackvein.quests.quests.BukkitObjective;
|
||||
import me.blackvein.quests.quests.BukkitQuestFactory;
|
||||
import me.blackvein.quests.quests.IQuest;
|
||||
import me.blackvein.quests.quests.IStage;
|
||||
import me.blackvein.quests.quests.Objective;
|
||||
import me.blackvein.quests.quests.Options;
|
||||
import me.blackvein.quests.quests.Planner;
|
||||
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");
|
||||
boolean failed = false;
|
||||
String failedQuest = "NULL";
|
||||
final List<IQuest> temp = new LinkedList<>();
|
||||
final List<String> temp = new LinkedList<>();
|
||||
for (final String node : nodes) {
|
||||
boolean done = false;
|
||||
for (final String id : questsSection.getKeys(false)) {
|
||||
final String node2 = config.getString("quests." + id + ".name");
|
||||
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node)
|
||||
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) {
|
||||
if (getQuestTemp(node) != null) {
|
||||
temp.add(getQuestTemp(node));
|
||||
} else if (getQuestByIdTemp(node) != null) {
|
||||
temp.add(getQuestByIdTemp(node));
|
||||
if (id.equals(node)) {
|
||||
if (getQuestByIdTemp(node) != null) {
|
||||
temp.add(node);
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement quest-blocks has unknown quest name/id "
|
||||
+ node + ", place it earlier in file so it loads first", questKey);
|
||||
throw new QuestFormatException("Requirement quest-blocks has unknown quest ID "
|
||||
+ node + ", manually update it to a valid ID", questKey);
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
@ -2400,9 +2393,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
||||
break;
|
||||
}
|
||||
}
|
||||
requires.setBlockQuests(temp);
|
||||
requires.setBlockQuestIds(temp);
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
@ -2414,20 +2407,16 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
||||
final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quests");
|
||||
boolean failed = false;
|
||||
String failedQuest = "NULL";
|
||||
final List<IQuest> temp = new LinkedList<>();
|
||||
final List<String> temp = new LinkedList<>();
|
||||
for (final String node : nodes) {
|
||||
boolean done = false;
|
||||
for (final String id : questsSection.getKeys(false)) {
|
||||
final String node2 = config.getString("quests." + id + ".name");
|
||||
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node)
|
||||
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) {
|
||||
if (getQuestTemp(node) != null) {
|
||||
temp.add(getQuestTemp(node));
|
||||
} else if (getQuestByIdTemp(node) != null) {
|
||||
temp.add(getQuestByIdTemp(node));
|
||||
if (id.equals(node)) {
|
||||
if (getQuestByIdTemp(node) != null) {
|
||||
temp.add(node);
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement quests has unknown quest name "
|
||||
+ node + ", place it earlier in file so it loads first", questKey);
|
||||
throw new QuestFormatException("Requirement quests has unknown quest ID "
|
||||
+ node + ", manually update it to a valid ID", questKey);
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
@ -2439,9 +2428,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
||||
break;
|
||||
}
|
||||
}
|
||||
requires.setNeededQuests(temp);
|
||||
requires.setNeededQuestIds(temp);
|
||||
if (failed) {
|
||||
throw new QuestFormatException("Requirement quests has invalid quest name/id "
|
||||
throw new QuestFormatException("Requirement quests has invalid quest ID "
|
||||
+ failedQuest, questKey);
|
||||
}
|
||||
} else {
|
||||
|
@ -155,17 +155,15 @@ public class QuestCommandHandler {
|
||||
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
|
||||
}
|
||||
}
|
||||
if (!reqs.getMcmmoSkills().isEmpty()) {
|
||||
for (final String skill : reqs.getMcmmoSkills()) {
|
||||
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
|
||||
.getMcMMOSkill(skill), player.getName());
|
||||
final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
|
||||
final String skillName = MiscUtil.getCapitalized(skill);
|
||||
if (level >= req) {
|
||||
cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
|
||||
}
|
||||
for (final String skill : reqs.getMcmmoSkills()) {
|
||||
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
|
||||
.getMcMMOSkill(skill), player.getName());
|
||||
final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
|
||||
final String skillName = MiscUtil.getCapitalized(skill);
|
||||
if (level >= req) {
|
||||
cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
|
||||
}
|
||||
}
|
||||
if (reqs.getQuestPoints() != 0) {
|
||||
@ -191,39 +189,33 @@ public class QuestCommandHandler {
|
||||
.currencyNameSingular()));
|
||||
}
|
||||
}
|
||||
if (!reqs.getItems().isEmpty()) {
|
||||
for (final ItemStack is : reqs.getItems()) {
|
||||
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
|
||||
}
|
||||
for (final ItemStack is : reqs.getItems()) {
|
||||
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
|
||||
}
|
||||
}
|
||||
if (!reqs.getNeededQuests().isEmpty()) {
|
||||
for (final IQuest quest : reqs.getNeededQuests()) {
|
||||
if (quester.getCompletedQuestsTemp().contains(quest)) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
|
||||
+ ChatColor.ITALIC + quest.getName());
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " "
|
||||
+ ChatColor.ITALIC + quest.getName());
|
||||
}
|
||||
for (IQuest quest : quester.getCompletedQuestsTemp()) {
|
||||
if (reqs.getNeededQuestIds().contains(quest.getId())) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
|
||||
+ ChatColor.ITALIC + quest.getName());
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " "
|
||||
+ ChatColor.ITALIC + quest.getName());
|
||||
}
|
||||
}
|
||||
if (!reqs.getBlockQuests().isEmpty()) {
|
||||
for (final IQuest quest : reqs.getBlockQuests()) {
|
||||
if (quester.getCompletedQuestsTemp().contains(quest)) {
|
||||
String msg = Lang.get("haveCompleted");
|
||||
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
|
||||
+ quest.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg);
|
||||
} else {
|
||||
String msg = Lang.get("cannotComplete");
|
||||
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
|
||||
+ quest.getName() + ChatColor.GREEN);
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
|
||||
}
|
||||
for (IQuest quest : quester.getCompletedQuestsTemp()) {
|
||||
if (reqs.getBlockQuestIds().contains(quest.getId())) {
|
||||
String msg = Lang.get("haveCompleted");
|
||||
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
|
||||
+ quest.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg);
|
||||
} else {
|
||||
String msg = Lang.get("cannotComplete");
|
||||
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
|
||||
+ quest.getName() + ChatColor.GREEN);
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,8 +281,8 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
|
||||
final IQuest found = plugin.getQuestTemp(input);
|
||||
if (found != null) {
|
||||
for (final IQuest q : plugin.getLoadedQuests()) {
|
||||
if (q.getRequirements().getNeededQuests().contains(q)
|
||||
|| q.getRequirements().getBlockQuests().contains(q)) {
|
||||
if (q.getRequirements().getNeededQuestIds().contains(q.getId())
|
||||
|| q.getRequirements().getBlockQuestIds().contains(q.getId())) {
|
||||
used.add(q.getName());
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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_REMOVE, requirements.getRemoveItems());
|
||||
}
|
||||
if (!requirements.getNeededQuests().isEmpty()) {
|
||||
final List<String> ids = requirements.getNeededQuests().stream().map(IQuest::getId).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST, ids);
|
||||
if (!requirements.getNeededQuestIds().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_QUEST, requirements.getNeededQuestIds());
|
||||
}
|
||||
if (!requirements.getBlockQuests().isEmpty()) {
|
||||
final List<String> ids = requirements.getBlockQuests().stream().map(IQuest::getId).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, ids);
|
||||
if (!requirements.getBlockQuestIds().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, requirements.getBlockQuestIds());
|
||||
}
|
||||
if (!requirements.getMcmmoSkills().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_MCMMO_SKILLS, requirements.getMcmmoAmounts());
|
||||
|
@ -25,8 +25,8 @@ public class BukkitRequirements implements Requirements {
|
||||
private int exp = 0;
|
||||
private List<ItemStack> items = new LinkedList<>();
|
||||
private List<Boolean> removeItems = new LinkedList<>();
|
||||
private List<IQuest> neededQuests = new LinkedList<>();
|
||||
private List<IQuest> blockQuests = new LinkedList<>();
|
||||
private List<String> neededQuestIds = new LinkedList<>();
|
||||
private List<String> blockQuestIds = new LinkedList<>();
|
||||
private List<String> permissions = new LinkedList<>();
|
||||
private List<String> mcmmoSkills = new LinkedList<>();
|
||||
private List<Integer> mcmmoAmounts = new LinkedList<>();
|
||||
@ -65,17 +65,17 @@ public class BukkitRequirements implements Requirements {
|
||||
public void setRemoveItems(final List<Boolean> removeItems) {
|
||||
this.removeItems = removeItems;
|
||||
}
|
||||
public List<IQuest> getNeededQuests() {
|
||||
return neededQuests;
|
||||
public List<String> getNeededQuestIds() {
|
||||
return neededQuestIds;
|
||||
}
|
||||
public void setNeededQuests(final List<IQuest> neededQuests) {
|
||||
this.neededQuests = neededQuests;
|
||||
public void setNeededQuestIds(final List<String> neededQuestIds) {
|
||||
this.neededQuestIds = neededQuestIds;
|
||||
}
|
||||
public List<IQuest> getBlockQuests() {
|
||||
return blockQuests;
|
||||
public List<String> getBlockQuestIds() {
|
||||
return blockQuestIds;
|
||||
}
|
||||
public void setBlockQuests(final List<IQuest> blockQuests) {
|
||||
this.blockQuests = blockQuests;
|
||||
public void setBlockQuestIds(final List<String> blockQuestIds) {
|
||||
this.blockQuestIds = blockQuestIds;
|
||||
}
|
||||
public List<String> getPermissions() {
|
||||
return permissions;
|
||||
@ -127,8 +127,8 @@ public class BukkitRequirements implements Requirements {
|
||||
if (exp != 0) { return true; }
|
||||
if (!items.isEmpty()) { return true; }
|
||||
if (!removeItems.isEmpty()) { return true; }
|
||||
if (!neededQuests.isEmpty()) { return true; }
|
||||
if (!blockQuests.isEmpty()) { return true; }
|
||||
if (!neededQuestIds.isEmpty()) { return true; }
|
||||
if (!blockQuestIds.isEmpty()) { return true; }
|
||||
if (!permissions.isEmpty()) { return true; }
|
||||
if (!mcmmoSkills.isEmpty()) { return true; }
|
||||
if (!mcmmoAmounts.isEmpty()) { return true; }
|
||||
|
Loading…
Reference in New Issue
Block a user