Fixed quest triggers for the next objective not triggering

This commit is contained in:
Jules 2024-05-23 23:47:13 -07:00
parent 6e739b3787
commit 2a17aa1a58

View File

@ -5,63 +5,63 @@ import net.Indyuce.mmocore.api.quest.objective.Objective;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
public class QuestProgress { public class QuestProgress {
private final Quest quest; private final Quest quest;
private final PlayerData player; private final PlayerData player;
private int objective; private int objective;
private ObjectiveProgress objectiveProgress; private ObjectiveProgress objectiveProgress;
public QuestProgress(Quest quest, PlayerData player) { public QuestProgress(Quest quest, PlayerData player) {
this(quest, player, 0); this(quest, player, 0);
} }
public QuestProgress(Quest quest, PlayerData player, int objective) { public QuestProgress(Quest quest, PlayerData player, int objective) {
this.quest = quest; this.quest = quest;
this.player = player; this.player = player;
this.objective = objective;
objectiveProgress = nextObjective().newProgress(this);
}
public Quest getQuest() { this.objective = objective;
return quest; objectiveProgress = nextObjective().newProgress(this);
} }
public PlayerData getPlayer() { public Quest getQuest() {
return player; return quest;
} }
public int getObjectiveNumber() { public PlayerData getPlayer() {
return objective; return player;
} }
public ObjectiveProgress getProgress() { public int getObjectiveNumber() {
return objectiveProgress; return objective;
} }
private Objective nextObjective() { public ObjectiveProgress getProgress() {
return quest.getObjectives().get(objective); return objectiveProgress;
} }
public void completeObjective() { private Objective nextObjective() {
objective++; return quest.getObjectives().get(objective);
objectiveProgress.close(); }
public void completeObjective() {
objective++;
objectiveProgress.close();
final ObjectiveProgress finishedObjectiveProgress = objectiveProgress;
// end quest // Start next objective, or end quest.
if (objective >= quest.getObjectives().size()) if (objective >= quest.getObjectives().size()) player.getQuestData().finishCurrent();
player.getQuestData().finishCurrent(); else objectiveProgress = nextObjective().newProgress(this);
else
objectiveProgress = nextObjective().newProgress(this);
player.getQuestData().updateBossBar(); player.getQuestData().updateBossBar();
/*
* Apply triggers only at the end! It comes handy when starting another
* quest in some storyline using triggers from the previous quest.
*/
finishedObjectiveProgress.getObjective().getTriggers().forEach(trigger -> trigger.schedule(getPlayer()));
}
// apply triggers at the end so the quest is ended when a trigger quest start is launched. public String getFormattedLore() {
objectiveProgress.getObjective().getTriggers().forEach(trigger -> trigger.schedule(getPlayer())); return MythicLib.plugin.parseColors(objectiveProgress.formatLore(objectiveProgress.getObjective().getDefaultLore()));
} }
public String getFormattedLore() {
return MythicLib.plugin.parseColors(objectiveProgress.formatLore(objectiveProgress.getObjective().getDefaultLore()));
}
} }