Skip to content

Commit

Permalink
Moved quest description logic out of the branches manager
Browse files Browse the repository at this point in the history
  • Loading branch information
SkytAsul committed Jun 17, 2022
1 parent 9d314a6 commit 200bb8d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void setItems(){
Quest qu = quests.get(i);
ItemStack item;
try {
String desc = qu.getBranchesManager().getDescriptionLine(acc, Source.MENU);
String desc = qu.getDescriptionLine(acc, Source.MENU);
List<String> lore = new ArrayList<>(4);
if (desc != null && !desc.isEmpty()) lore.add(desc);
boolean hasDialogs = QuestsConfiguration.getDialogsConfig().isHistoryEnabled() && acc.getQuestDatas(qu).hasFlowDialogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private boolean tryRefresh(boolean time) {
text = shown == null ? Lang.SCOREBOARD_NONE_NAME.toString() : text.replace("{questName}", shown.getName());
}
if (text.contains("{questDescription}")) {
text = shown == null ? Lang.SCOREBOARD_NONE_DESC.toString() : text.replace("{questDescription}", shown.getBranchesManager().getDescriptionLine(acc, Source.SCOREBOARD));
text = shown == null ? Lang.SCOREBOARD_NONE_DESC.toString() : text.replace("{questDescription}", shown.getDescriptionLine(acc, Source.SCOREBOARD));
}
text = Utils.finalFormat(p, text, true);
if (text.equals(lastValue)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import fr.skytasul.quests.BeautyQuests;
import fr.skytasul.quests.api.QuestsAPI;
import fr.skytasul.quests.players.PlayerAccount;
import fr.skytasul.quests.players.PlayerQuestDatas;
import fr.skytasul.quests.structure.QuestBranch.Source;
import fr.skytasul.quests.utils.Lang;

public class BranchesManager{

Expand Down Expand Up @@ -68,13 +65,6 @@ public boolean hasBranchStarted(PlayerAccount acc, QuestBranch branch){
return acc.getQuestDatas(quest).getBranch() == branch.getID();
}

public String getDescriptionLine(PlayerAccount acc, Source source) {
if (!acc.hasQuestDatas(quest)) throw new IllegalArgumentException("Account do not have quest datas");
PlayerQuestDatas datas = acc.getQuestDatas(quest);
if (datas.isInQuestEnd()) return Lang.SCOREBOARD_ASYNC_END.toString();
return branches.get(datas.getBranch()).getDescriptionLine(acc, source);
}

/**
* Called internally when the quest is updated for the player
* @param p Player
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/fr/skytasul/quests/structure/Quest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import fr.skytasul.quests.players.PlayerQuestDatas;
import fr.skytasul.quests.players.PlayersManager;
import fr.skytasul.quests.rewards.MessageReward;
import fr.skytasul.quests.structure.QuestBranch.Source;
import fr.skytasul.quests.utils.DebugUtils;
import fr.skytasul.quests.utils.Lang;
import fr.skytasul.quests.utils.Utils;
Expand Down Expand Up @@ -259,6 +260,16 @@ public void leave(Player p) {
getOption(OptionStartDialog.class).getDialogRunner().removePlayer(p);
}
}

public String getDescriptionLine(PlayerAccount acc, Source source) {
if (!acc.hasQuestDatas(this)) throw new IllegalArgumentException("Account does not have quest datas for quest " + id);
if (asyncStart != null && acc.isCurrent() && asyncStart.contains(acc.getPlayer())) return "§7x";
PlayerQuestDatas datas = acc.getQuestDatas(this);
if (datas.isInQuestEnd()) return Lang.SCOREBOARD_ASYNC_END.toString();
QuestBranch branch = manager.getBranch(datas.getBranch());
if (branch == null) throw new IllegalStateException("Account is in branch " + datas.getBranch() + " in quest " + id + ", which does not actually exist");
return branch.getDescriptionLine(acc, source);
}

public void attemptStart(Player p, Runnable atStart) {
String confirm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -123,7 +123,7 @@ public String onRequest(OfflinePlayer off, String identifier) {
.filter(Objects::nonNull)
.filter(Quest::isScoreboardEnabled)
.map(quest -> {
String desc = quest.getBranchesManager().getDescriptionLine(acc, Source.PLACEHOLDER);
String desc = quest.getDescriptionLine(acc, Source.PLACEHOLDER);
return inlineFormat
.replace("{questName}", quest.getName())
.replace("{questDescription}", desc);
Expand Down Expand Up @@ -163,7 +163,7 @@ public String onRequest(OfflinePlayer off, String identifier) {
if (data.left.isEmpty()) return i == -1 || i == 0 ? Lang.SCOREBOARD_NONE.toString() : "";

Quest quest = data.left.get(0);
String desc = quest.getBranchesManager().getDescriptionLine(acc, Source.PLACEHOLDER);
String desc = quest.getDescriptionLine(acc, Source.PLACEHOLDER);
String format = noSplit ? inlineFormat : splitFormat;
format = format.replace("{questName}", quest.getName()).replace("{questDescription}", desc);

Expand Down Expand Up @@ -194,7 +194,7 @@ public String onRequest(OfflinePlayer off, String identifier) {
if (qu == null) return "§c§lError: unknown quest §o" + sid;
if (rawId == -1) {
if (qu.hasStarted(acc)) {
return qu.getBranchesManager().getDescriptionLine(acc, Source.PLACEHOLDER);
return qu.getDescriptionLine(acc, Source.PLACEHOLDER);
}
if (qu.hasFinished(acc)) return Lang.Finished.toString();
return Lang.Not_Started.toString();
Expand Down

0 comments on commit 200bb8d

Please sign in to comment.